Golang expvar.Func type and String() function example
package expvar
Func implements Var by calling the function and formatting the returned value using JSON.
Golang expvar.Func type and String() function usage example
package main
import (
"expvar"
"fmt"
)
func main() {
var x interface{} = `{"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}`
f := expvar.Func(func() interface{} { return x })
str := f.String()
fmt.Println(str) // JSON value
}
References :
Advertisement
Something interesting
Tutorials
+9.4k Golang : Apply Histogram Equalization to color images
+11.5k Golang : Handle API query by curl with Gorilla Queries example
+38.1k Golang : Read a text file and replace certain words
+24.5k Golang : GORM read from database example
+13.9k Golang : How to determine if a year is leap year?
+8.1k Golang : Variadic function arguments sanity check example
+10.5k Golang : Select region of interest with mouse click and crop from image
+11k Golang : Generate random elements without repetition or duplicate
+18.5k Golang : Example for RSA package functions
+26.3k Golang : Calculate future date with time.Add() function
+7.9k Javascript : How to check a browser's Do Not Track status?