Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(772)

Unified Diff: luci_config/server/cfgclient/backend/get_all.go

Issue 2580713002: Implement a server-side config service interface. (Closed)
Patch Set: Renamed, moved to luci_config package, fixes, split out backends. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « luci_config/server/cfgclient/backend/gen.go ('k') | luci_config/server/cfgclient/backend/meta.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: luci_config/server/cfgclient/backend/get_all.go
diff --git a/luci_config/server/cfgclient/backend/get_all.go b/luci_config/server/cfgclient/backend/get_all.go
new file mode 100644
index 0000000000000000000000000000000000000000..a789e85dc3b785cf9fad6d92eaaa657562126622
--- /dev/null
+++ b/luci_config/server/cfgclient/backend/get_all.go
@@ -0,0 +1,54 @@
+// Copyright 2016 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package backend
+
+import (
+ "bytes"
+
+ "github.com/luci/luci-go/common/errors"
+)
+
+// GetAllTarget is the type of configuration to retrieve with GetAll.
+//
+// GetAllTarget marshals/unmarshals to/from a compact JSON representation. This is
+// used by the caching layer.
+type GetAllTarget string
+
+const (
+ // GetAllProject indicates that project configus should be retrieved.
+ GetAllProject = GetAllTarget("Project")
+ // GetAllRef indicates that ref configs should be retrieved.
+ GetAllRef = GetAllTarget("Ref")
+)
+
+var (
+ projectJSON = []byte(`"P"`)
+ refJSON = []byte(`"R"`)
+)
+
+// MarshalJSON implements json.Marshaler.
+func (gat GetAllTarget) MarshalJSON() ([]byte, error) {
+ switch gat {
+ case GetAllProject:
+ return projectJSON, nil
+ case GetAllRef:
+ return refJSON, nil
+ default:
+ return nil, errors.Reason("unknown GetAllTarget: %(value)v").D("value", gat).Err()
+ }
+}
+
+// UnmarshalJSON implements json.Unmarshaler.
+func (gat *GetAllTarget) UnmarshalJSON(d []byte) error {
+ switch {
+ case bytes.Equal(d, projectJSON):
+ *gat = GetAllProject
+ case bytes.Equal(d, refJSON):
+ *gat = GetAllRef
+ default:
+ return errors.Reason("unknown GetAllTarget: %(value)q").D("value", d).Err()
+ }
+ return nil
+}
« no previous file with comments | « luci_config/server/cfgclient/backend/gen.go ('k') | luci_config/server/cfgclient/backend/meta.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698