本站源代码
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

26 lines
761B

  1. // Copyright 2012 Google Inc. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package appengine
  5. import (
  6. "fmt"
  7. "regexp"
  8. "golang.org/x/net/context"
  9. "google.golang.org/appengine/internal"
  10. )
  11. // Namespace returns a replacement context that operates within the given namespace.
  12. func Namespace(c context.Context, namespace string) (context.Context, error) {
  13. if !validNamespace.MatchString(namespace) {
  14. return nil, fmt.Errorf("appengine: namespace %q does not match /%s/", namespace, validNamespace)
  15. }
  16. return internal.NamespacedContext(c, namespace), nil
  17. }
  18. // validNamespace matches valid namespace names.
  19. var validNamespace = regexp.MustCompile(`^[0-9A-Za-z._-]{0,100}$`)
上海开阖软件有限公司 沪ICP备12045867号-1