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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package backend
6
7 import (
8 "bytes"
9
10 "github.com/luci/luci-go/common/errors"
11 )
12
13 // GetAllTarget is the type of configuration to retrieve with GetAll.
14 //
15 // GetAllTarget marshals/unmarshals to/from a compact JSON representation. This is
16 // used by the caching layer.
17 type GetAllTarget string
18
19 const (
20 // GetAllProject indicates that project configus should be retrieved.
21 GetAllProject = GetAllTarget("Project")
22 // GetAllRef indicates that ref configs should be retrieved.
23 GetAllRef = GetAllTarget("Ref")
24 )
25
26 var (
27 projectJSON = []byte(`"P"`)
28 refJSON = []byte(`"R"`)
29 )
30
31 // MarshalJSON implements json.Marshaler.
32 func (gat GetAllTarget) MarshalJSON() ([]byte, error) {
33 switch gat {
34 case GetAllProject:
35 return projectJSON, nil
36 case GetAllRef:
37 return refJSON, nil
38 default:
39 return nil, errors.Reason("unknown GetAllTarget: %(value)v").D(" value", gat).Err()
40 }
41 }
42
43 // UnmarshalJSON implements json.Unmarshaler.
44 func (gat *GetAllTarget) UnmarshalJSON(d []byte) error {
45 switch {
46 case bytes.Equal(d, projectJSON):
47 *gat = GetAllProject
48 case bytes.Equal(d, refJSON):
49 *gat = GetAllRef
50 default:
51 return errors.Reason("unknown GetAllTarget: %(value)q").D("value ", d).Err()
52 }
53 return nil
54 }
OLDNEW
« 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