// snapshotMap recursively walks expvar Maps and records their integer expvars // in a separate flat map. func snapshotMap(varsMap map[string]int64, path string, mp *expvar.Map) { mp.Do(func(kv expvar.KeyValue) { switch kv.Value.(type) { case *expvar.Int: varsMap[path+"."+kv.Key], _ = strconv.ParseInt(kv.Value.String(), 10, 64) case *expvar.Map: snapshotMap(varsMap, path+"."+kv.Key, kv.Value.(*expvar.Map)) } }) }
func resetVarMap(varMap *expvar.Map) { // There is no easy way to delete/clear expvar.Map. As such there is a slight // race here. *sigh* keys := []string{} varMap.Do(func(kv expvar.KeyValue) { keys = append(keys, kv.Key) }) for _, key := range keys { varMap.Set(key, new(expvar.Int)) } }