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

Side by Side Diff: luci_config/server/cfgclient/format.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
« no previous file with comments | « luci_config/server/cfgclient/doc.go ('k') | luci_config/server/cfgclient/naming.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 cfgclient
6
7 import (
8 "fmt"
9 "sync"
10 )
11
12 // Formatter applies a transformation to the data's cached representation.
13 //
14 // The Formatter is supplied with the content to format along with the
15 // formatter-specific metadata, fd.
16 //
17 // Formatter operates on a backend.Item's Content via the "format" Backend.
18 type Formatter interface {
19 FormatItem(c, fd string) (string, error)
20 }
21
22 // FormatterRegistry is a registry of Resolver key mapped to the Formatter to
23 // use to format that key.
24 type FormatterRegistry struct {
25 registryMu sync.RWMutex
26 registry map[string]Formatter
27 }
28
29 // Register registers a Formatter with the FormatBackend.
30 //
31 // If the supplied key is already registered, Register will panic.
32 func (r *FormatterRegistry) Register(rk string, f Formatter) {
33 if rk == "" {
34 panic("cannot register empty key")
35 }
36
37 r.registryMu.Lock()
38 defer r.registryMu.Unlock()
39
40 if _, ok := r.registry[rk]; ok {
41 panic(fmt.Errorf("key %q is already registered", rk))
42 }
43 if r.registry == nil {
44 r.registry = map[string]Formatter{}
45 }
46 r.registry[rk] = f
47 }
48
49 // Get returns the Formatter associated with the provided Format.
50 func (r *FormatterRegistry) Get(f string) Formatter {
51 r.registryMu.RLock()
52 defer r.registryMu.RUnlock()
53 return r.registry[f]
54 }
OLDNEW
« no previous file with comments | « luci_config/server/cfgclient/doc.go ('k') | luci_config/server/cfgclient/naming.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698