diff options
Diffstat (limited to 'docshelper/docs.go')
-rw-r--r-- | docshelper/docs.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/docshelper/docs.go b/docshelper/docs.go index 94cb70dec..17e0ccd91 100644 --- a/docshelper/docs.go +++ b/docshelper/docs.go @@ -24,7 +24,11 @@ var DocProviders = make(map[string]DocProvider) // AddDocProvider adds or updates the DocProvider for a given name. func AddDocProvider(name string, provider DocProvider) { - DocProviders[name] = provider + if prev, ok := DocProviders[name]; !ok { + DocProviders[name] = provider + } else { + DocProviders[name] = merge(prev, provider) + } } // DocProvider is used to save arbitrary JSON data @@ -35,3 +39,13 @@ type DocProvider func() map[string]interface{} func (d DocProvider) MarshalJSON() ([]byte, error) { return json.MarshalIndent(d(), "", " ") } + +func merge(a, b DocProvider) DocProvider { + next := a() + for k, v := range b() { + next[k] = v + } + return func() map[string]interface{} { + return next + } +} |