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
+8.4k Your page has meta tags in the body instead of the head
+25.7k Golang : How to write CSV data to file
+9k Golang : automatically figure out array length(size) with three dots
+5.4k Golang : Get S3 or CloudFront object or file information
+5.2k Golang : Customize scanner.Scanner to treat dash as part of identifier
+14.3k Golang : How to shuffle elements in array or slice?
+18.5k Golang : Write file with io.WriteString
+7.3k Golang : Not able to grep log.Println() output
+4.9k Python : Find out the variable type and determine the type with simple test
+13.6k Golang : Set image canvas or background to transparent
+17.7k Golang : Read data from config file and assign to variables