Golang expvar.KeyValue type example
package expvar
KeyValue represents a single entry in a Map.
Golang expvar.KeyValue type usage example
package main
import (
"fmt"
"net/http"
"expvar"
)
func kvfunc(kv expvar.KeyValue) { // <-- here
fmt.Println(kv.Key, kv.Value)
}
func main() {
var inerInt int64 = 10
pubInt := expvar.NewInt("Int")
pubInt.Set(inerInt)
pubInt.Add(2)
var inerFloat float64 = 1.2
pubFloat := expvar.NewFloat("Float")
pubFloat.Set(inerFloat)
pubFloat.Add(0.1)
var inerString string = "hello gophers"
pubString := expvar.NewString("String")
pubString.Set(inerString)
pubMap := expvar.NewMap("Map").Init()
pubMap.Set("Int", pubInt)
pubMap.Set("Float", pubFloat)
pubMap.Set("String", pubString)
pubMap.Add("Int", 1)
pubMap.Add("NewInt", 123)
pubMap.AddFloat("Float", 0.5)
pubMap.AddFloat("NewFloat", 0.9)
pubMap.Do(kvfunc)
expvar.Do(kvfunc)
http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "hello gophers")
})
err := http.ListenAndServe(":8080", nil)
if err != nil {
panic(err)
}
}
Reference :
Advertisement
Something interesting
Tutorials
+5.5k Golang : If else example and common mistake
+10.2k Golang : Text file editor (accept input from screen and save to file)
+9.5k Golang : Convert(cast) string to int64
+10.1k Golang : Identifying Golang HTTP client request
+18.5k Golang : Aligning strings to right, left and center with fill example
+14k Golang : Reverse IP address for reverse DNS lookup example
+8.5k Golang : How to check if input string is a word?
+6.5k Elasticsearch : Shutdown a local node
+12.6k Golang : Exit, terminating or aborting a program
+8.8k Golang : HTTP Routing with Goji example
+15.6k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+31.5k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions