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
+15.2k Golang : Save(pipe) HTTP response into a file
+5.2k Golang : Convert lines of string into list for delete and insert operation
+4.7k Linux/MacOSX : How to symlink a file?
+8.1k Golang : Check from web if Go application is running or not
+46.4k Golang : Encode image to base64 example
+15.2k Golang : Get HTTP protocol version example
+15k Golang : package is not in GOROOT during compilation
+13k Golang : Get terminal width and height example
+20.5k nginx: [emerg] unknown directive "passenger_enabled"
+14.8k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+5.8k Golang : Find change in a combination of coins example
+10k Golang : Get escape characters \u form from unicode characters