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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: luci_config/server/cfgclient/format.go
diff --git a/luci_config/server/cfgclient/format.go b/luci_config/server/cfgclient/format.go
new file mode 100644
index 0000000000000000000000000000000000000000..ef1620c148f7348735f4fff0d6beae521267e4a2
--- /dev/null
+++ b/luci_config/server/cfgclient/format.go
@@ -0,0 +1,54 @@
+// Copyright 2016 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package cfgclient
+
+import (
+ "fmt"
+ "sync"
+)
+
+// Formatter applies a transformation to the data's cached representation.
+//
+// The Formatter is supplied with the content to format along with the
+// formatter-specific metadata, fd.
+//
+// Formatter operates on a backend.Item's Content via the "format" Backend.
+type Formatter interface {
+ FormatItem(c, fd string) (string, error)
+}
+
+// FormatterRegistry is a registry of Resolver key mapped to the Formatter to
+// use to format that key.
+type FormatterRegistry struct {
+ registryMu sync.RWMutex
+ registry map[string]Formatter
+}
+
+// Register registers a Formatter with the FormatBackend.
+//
+// If the supplied key is already registered, Register will panic.
+func (r *FormatterRegistry) Register(rk string, f Formatter) {
+ if rk == "" {
+ panic("cannot register empty key")
+ }
+
+ r.registryMu.Lock()
+ defer r.registryMu.Unlock()
+
+ if _, ok := r.registry[rk]; ok {
+ panic(fmt.Errorf("key %q is already registered", rk))
+ }
+ if r.registry == nil {
+ r.registry = map[string]Formatter{}
+ }
+ r.registry[rk] = f
+}
+
+// Get returns the Formatter associated with the provided Format.
+func (r *FormatterRegistry) Get(f string) Formatter {
+ r.registryMu.RLock()
+ defer r.registryMu.RUnlock()
+ return r.registry[f]
+}
« 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