1 Star 0 Fork 0

zhuchance/kubernetes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
namespace.go 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
// Copyright 2012 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package appengine
import (
"fmt"
"regexp"
"github.com/golang/protobuf/proto"
"google.golang.org/appengine/internal"
basepb "google.golang.org/appengine/internal/base"
)
// Namespace returns a replacement context that operates within the given namespace.
func Namespace(c Context, namespace string) (Context, error) {
if !validNamespace.MatchString(namespace) {
return nil, fmt.Errorf("appengine: namespace %q does not match /%s/", namespace, validNamespace)
}
return &namespacedContext{
Context: c,
namespace: namespace,
}, nil
}
// validNamespace matches valid namespace names.
var validNamespace = regexp.MustCompile(`^[0-9A-Za-z._-]{0,100}$`)
// namespacedContext wraps a Context to support namespaces.
type namespacedContext struct {
Context
namespace string
}
func (n *namespacedContext) Call(service, method string, in, out proto.Message, opts *internal.CallOptions) error {
// Apply any namespace mods.
if mod, ok := internal.NamespaceMods[service]; ok {
mod(in, n.namespace)
}
if service == "__go__" && method == "GetNamespace" {
out.(*basepb.StringProto).Value = proto.String(n.namespace)
return nil
}
return n.Context.Call(service, method, in, out, opts)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/meoom/kubernetes.git
git@gitee.com:meoom/kubernetes.git
meoom
kubernetes
kubernetes
v0.14.1

搜索帮助

Cb406eda 1850385 E526c682 1850385