Skip to content

Commit e05664f

Browse files
authored
Document GetOrCreateRegistry, deprecate NewRegistry (#343)
Documentation only: Add doc comments deprecating the `NewRegistry` method (which is being phased out because it panics if the same name is used more than once) and documenting its mostly-drop-in replacement `GetOrCreateRegistry`.
1 parent a46aee9 commit e05664f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

monitoring/registry.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,15 @@ func (r *Registry) doVisit(mode Mode, vs Visitor) {
8383
}
8484

8585
vs.OnKey(key)
86-
v.Var.Visit(mode, vs)
86+
v.Visit(mode, vs)
8787
}
8888
}
8989

90-
// NewRegistry creates and register a new registry
90+
// NewRegistry creates and registers a new registry. Panics if there is already
91+
// a variable or registry with the same name.
92+
//
93+
// Deprecated: Use GetOrCreateRegistry instead, which does not panic if the
94+
// given name already exists.
9195
func (r *Registry) NewRegistry(name string, opts ...Option) *Registry {
9296
v := &Registry{
9397
name: fullName(r, name),
@@ -134,6 +138,12 @@ func (r *Registry) newRegistryChainWithLock(names []string, opts *options) *Regi
134138
return cur
135139
}
136140

141+
// GetOrCreateRegistry creates and returns a new registry with the specified
142+
// name or path under the given parent, or returns the existing registry if
143+
// one with that name already exists.
144+
//
145+
// If the name exists but refers to a non-registry variable,
146+
// GetOrCreateRegistry returns nil.
137147
func (r *Registry) GetOrCreateRegistry(name string, opts ...Option) *Registry {
138148
names := strings.Split(name, ".")
139149
return r.getOrCreateRegistry(names, opts...)

0 commit comments

Comments
 (0)