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
+20.7k Golang : Read directory content with os.Open
+15.3k Golang : How to get Unix file descriptor for console and file
+4.9k JQuery : Calling a function inside Jquery(document) block
+23.1k Golang : Randomly pick an item from a slice/array example
+5.9k AWS S3 : Prevent Hotlinking policy
+6.9k Golang : Calculate BMI and risk category
+8.9k Golang : Sort lines of text example
+16.4k Golang : Convert slice to array
+8.3k Golang : Implementing class(object-oriented programming style)
+15.8k Golang : How to login and logout with JWT example
+7.9k Golang : Grayscale Image
+11.9k Golang : How to parse plain email text and process email header?