You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
761 B

  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}$`)