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 cfgclient | 5 package cfgclient |
6 | 6 |
7 import ( | 7 import ( |
8 "github.com/luci/luci-go/common/errors" | 8 "github.com/luci/luci-go/common/errors" |
9 "github.com/luci/luci-go/luci_config/server/cfgclient/backend" | 9 "github.com/luci/luci-go/luci_config/server/cfgclient/backend" |
10 ) | 10 ) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // Format returns the FormatterRegistry key and associated data for this | 43 // Format returns the FormatterRegistry key and associated data for this |
44 // Resolver. | 44 // Resolver. |
45 // | 45 // |
46 // An empty format represents no Formatter, meaning that this Resolver o
nly | 46 // An empty format represents no Formatter, meaning that this Resolver o
nly |
47 // supports the raw config service result. | 47 // supports the raw config service result. |
48 Format() backend.FormatSpec | 48 Format() backend.FormatSpec |
49 } | 49 } |
50 | 50 |
51 func assertEmptyFormat(it *backend.Item) error { | 51 func assertEmptyFormat(it *backend.Item) error { |
52 if !it.FormatSpec.Unformatted() { | 52 if !it.FormatSpec.Unformatted() { |
53 » » return errors.Reason("unknown format: %(format)q").D("format", i
t.FormatSpec.Formatter).Err() | 53 » » return errors.Reason("unknown format: %q", it.FormatSpec.Formatt
er).Err() |
54 } | 54 } |
55 return nil | 55 return nil |
56 } | 56 } |
57 | 57 |
58 // Bytes is a Resolver that resolves config data into a byte slice. | 58 // Bytes is a Resolver that resolves config data into a byte slice. |
59 func Bytes(out *[]byte) Resolver { return byteSliceResolver{out} } | 59 func Bytes(out *[]byte) Resolver { return byteSliceResolver{out} } |
60 | 60 |
61 // BytesSlice is a MultiResolver that resolves condig data into a slice of byte | 61 // BytesSlice is a MultiResolver that resolves condig data into a slice of byte |
62 // slices. | 62 // slices. |
63 func BytesSlice(out *[][]byte) MultiResolver { return multiByteSliceResolver{out
} } | 63 func BytesSlice(out *[][]byte) MultiResolver { return multiByteSliceResolver{out
} } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 func (r multiStringResolver) ResolveItemAt(i int, it *backend.Item) error { | 132 func (r multiStringResolver) ResolveItemAt(i int, it *backend.Item) error { |
133 if err := assertEmptyFormat(it); err != nil { | 133 if err := assertEmptyFormat(it); err != nil { |
134 return err | 134 return err |
135 } | 135 } |
136 (*r.out)[i] = it.Content | 136 (*r.out)[i] = it.Content |
137 return nil | 137 return nil |
138 } | 138 } |
OLD | NEW |