parent
3ef9f6f016
commit
8ec57d145e
267 changed files with 15430 additions and 10511 deletions
29
vendor/google.golang.org/appengine/namespace.go
generated
vendored
29
vendor/google.golang.org/appengine/namespace.go
generated
vendored
|
@ -8,41 +8,18 @@ import (
|
|||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"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) {
|
||||
func Namespace(c context.Context, namespace string) (context.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
|
||||
return internal.NamespacedContext(c, 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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue