| OLD | NEW |
| (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 } |
| OLD | NEW |