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.1k Golang : Tell color name with OpenCV example
+29.7k Golang : Record voice(audio) from microphone to .WAV file
+7.4k Golang : Convert source code to assembly language
+9.5k Golang : Changing a RGBA image number of channels with OpenCV
+22.1k Golang : Repeat a character by multiple of x factor
+11.1k Golang : How to determine a prime number?
+23.9k Golang : Fix type interface{} has no field or no methods and type assertions example
+6.2k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+4k Detect if Google Analytics and Developer Media are loaded properly or not
+20.7k Golang : Read directory content with os.Open
+25.4k Golang : Convert long hexadecimal with strconv.ParseUint example
+28.5k Golang : Change a file last modified date and time