OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package meta | |
6 | |
7 import ( | |
8 "github.com/luci/gae/service/datastore" | |
9 "github.com/luci/luci-go/common/logging" | |
10 "golang.org/x/net/context" | |
11 ) | |
12 | |
13 // Namespaces returns a list of all of the namespaces in the datastore. | |
14 // | |
15 // This is done by issuing a datastore query for kind "__namespace__". The | |
16 // resulting keys will have IDs for the namespaces, namely: | |
17 // - The empty namespace will have integer ID 1. We ignore this. | |
18 // - Other namespaces will have string IDs. | |
19 func Namespaces(c context.Context) ([]string, error) { | |
dnj
2016/04/23 02:17:10
(This is also verbatim transplant from luci-go) w/
iannucci
2016/04/23 19:15:21
I'm not comfortable making the default API be GetA
dnj
2016/04/24 00:08:37
The problem with a query is that you still have to
| |
20 q := datastore.NewQuery("__namespace__").KeysOnly(true) | |
21 | |
22 // Query our datastore for the full set of namespaces. | |
23 var namespaceKeys []*datastore.Key | |
24 if err := datastore.Get(c).GetAll(q, &namespaceKeys); err != nil { | |
iannucci
2016/04/23 19:15:21
Note: this query will ONLY run in the default (emp
dnj
2016/04/24 00:08:37
So on live Datastore, I can execute a GQL query fo
| |
25 logging.WithError(err).Errorf(c, "Failed to execute namespace qu ery.") | |
26 return nil, err | |
27 } | |
28 | |
29 namespaces := make([]string, 0, len(namespaceKeys)) | |
30 for _, nk := range namespaceKeys { | |
31 if ns := nk.StringID(); ns != "" { | |
32 namespaces = append(namespaces, ns) | |
33 } | |
34 } | |
35 return namespaces, nil | |
36 } | |
OLD | NEW |