github.com/aristanetworks/goarista@v0.0.0-20240514173732-cca2755bbd44/monitor/helpers.go (about)

     1  // Copyright (c) 2021 Arista Networks, Inc.
     2  // Use of this source code is governed by the Apache License 2.0
     3  // that can be found in the COPYING file.
     4  
     5  package monitor
     6  
     7  import (
     8  	"expvar"
     9  	"fmt"
    10  	"strings"
    11  )
    12  
    13  // VarsToString gives a string with all exported variables
    14  // the returned string is in a pretty format.
    15  func VarsToString() string {
    16  	sb := strings.Builder{}
    17  	sb.WriteString("{\n")
    18  	first := true
    19  	expvar.Do(func(kv expvar.KeyValue) {
    20  		if !first {
    21  			sb.WriteString(",\n")
    22  		}
    23  		first = false
    24  		sb.WriteString(fmt.Sprintf("\t%q: %s", kv.Key, kv.Value))
    25  	})
    26  	sb.WriteString("\n}")
    27  	return sb.String()
    28  }