Golang expvar.Float type, NewFloat(), Add() and Set() functions example
package expvar
Float is a 64-bit float variable that satisfies the Var interface.
Add() function adds delta to v.
Set() function sets v to value.
Golang expvar.Float type, NewFloat(), Add() and Set() functions usage example
package main
import (
"fmt"
"net/http"
"expvar"
)
func kvfunc(kv expvar.KeyValue) {
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") // <-- here
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) // <---- here
http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "hello gophers")
})
err := http.ListenAndServe(":8080", nil)
if err != nil {
panic(err)
}
}
References :
http://golang.org/pkg/expvar/#Float
http://golang.org/pkg/expvar/#NewFloat
Advertisement
Something interesting
Tutorials
+9.7k Golang : interface - when and where to use examples
+5.4k Python : Delay with time.sleep() function example
+28.2k Golang : Connect to database (MySQL/MariaDB) server
+7.6k Golang : Convert(cast) io.Reader type to string
+9.4k Golang : Create unique title slugs example
+5.8k Unix/Linux : Get reboot history or check when was the last reboot date
+24.5k Golang : GORM read from database example
+40.1k Golang : UDP client server read write example
+9k Golang : Capture text return from exec function example
+7.7k Golang : How to execute code at certain day, hour and minute?
+7.1k Nginx : How to block user agent ?