OLD | NEW |
1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package backend | 5 package backend |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 | 9 |
10 "github.com/luci/luci-go/common/errors" | 10 "github.com/luci/luci-go/common/errors" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // We use a shorthand notation so that we don't waste space in JSON. | 45 // We use a shorthand notation so that we don't waste space in JSON. |
46 func (a Authority) MarshalJSON() ([]byte, error) { | 46 func (a Authority) MarshalJSON() ([]byte, error) { |
47 switch a { | 47 switch a { |
48 case AsAnonymous: | 48 case AsAnonymous: |
49 return asAnonymousJSON, nil | 49 return asAnonymousJSON, nil |
50 case AsService: | 50 case AsService: |
51 return asServiceJSON, nil | 51 return asServiceJSON, nil |
52 case AsUser: | 52 case AsUser: |
53 return asUserJSON, nil | 53 return asUserJSON, nil |
54 default: | 54 default: |
55 » » return nil, errors.Reason("unknown authority: %(auth)v").D("auth
", a).Err() | 55 » » return nil, errors.Reason("unknown authority: %v", a).Err() |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 // UnmarshalJSON implements encoding/json.Unmarshaler. | 59 // UnmarshalJSON implements encoding/json.Unmarshaler. |
60 func (a *Authority) UnmarshalJSON(d []byte) error { | 60 func (a *Authority) UnmarshalJSON(d []byte) error { |
61 switch { | 61 switch { |
62 case bytes.Equal(d, asAnonymousJSON): | 62 case bytes.Equal(d, asAnonymousJSON): |
63 *a = AsAnonymous | 63 *a = AsAnonymous |
64 case bytes.Equal(d, asServiceJSON): | 64 case bytes.Equal(d, asServiceJSON): |
65 *a = AsService | 65 *a = AsService |
66 case bytes.Equal(d, asUserJSON): | 66 case bytes.Equal(d, asUserJSON): |
67 *a = AsUser | 67 *a = AsUser |
68 default: | 68 default: |
69 » » return errors.Reason("unknown authority JSON value: %(auth)v").D
("auth", d).Err() | 69 » » return errors.Reason("unknown authority JSON value: %v", d).Err(
) |
70 } | 70 } |
71 return nil | 71 return nil |
72 } | 72 } |
OLD | NEW |