Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expvar: make possible to delete all exported variables #34832

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/expvar/expvar.go
Expand Up @@ -283,6 +283,16 @@ func Publish(name string, v Var) {
sort.Strings(varKeys)
}

// RemoveAll removes all exported variables.
func RemoveAll() {
varKeysMu.Lock()
defer varKeysMu.Unlock()
for _, k := range varKeys {
vars.Delete(k)
}
varKeys = nil
}

// Get retrieves a named exported variable. It returns nil if the name has
// not been registered.
func Get(name string) Var {
Expand Down
11 changes: 0 additions & 11 deletions src/expvar/expvar_test.go
Expand Up @@ -19,17 +19,6 @@ import (
"testing"
)

// RemoveAll removes all exported variables.
// This is for tests only.
func RemoveAll() {
varKeysMu.Lock()
defer varKeysMu.Unlock()
for _, k := range varKeys {
vars.Delete(k)
}
varKeys = nil
}

func TestNil(t *testing.T) {
RemoveAll()
val := Get("missing")
Expand Down