Golang expvar.Var type and Get() function example
package expvar
Var type is an abstract type for all exported variables.
Get function retrieves a named exported variable.
Golang expvar.Var type usage example
type Graphite struct {
endpoint string
interval time.Duration
timeout time.Duration
connection net.Conn
vars map[string]expvar.Var
registrations chan namedVar
shutdown chan chan bool
}
g := &Graphite{
endpoint: endpoint,
interval: interval,
timeout: timeout,
connection: nil,
vars: map[string]expvar.Var{},
registrations: make(chan namedVar),
shutdown: make(chan chan bool),
}
Golang expvar.Get() function usage example
...
reqs := expvar.NewFloat("requests-float")
if reqs.f != 0.0 {
fmt.Printf("reqs.f = %v, want 0", reqs.f)
}
if reqs != expvar.Get("requests-float").(*Float) {
fmt.Printf("Get() failed.")
}
...
Advertisement
Something interesting
Tutorials
+25.3k Golang : Get current file path of a file or executable
+18.5k Golang : Aligning strings to right, left and center with fill example
+30.5k Golang : Generate random string
+7.8k Golang : Example of how to detect which type of script a word belongs to
+6.5k Golang : Convert an executable file into []byte example
+9.5k Golang : Convert(cast) string to int64
+62.7k Golang : Convert HTTP Response body to string
+13k Golang : Calculate elapsed years or months since a date
+16k Golang : How to reverse elements order in map ?
+16.3k Golang :Trim white spaces from a string
+9.3k Golang : Temperatures conversion example
+13.8k Generate salted password with OpenSSL example