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
+8.2k Golang : HttpRouter multiplexer routing example
+9.7k Golang : interface - when and where to use examples
+10.9k Golang : Sieve of Eratosthenes algorithm
+6.6k Golang : Embedded or data bundling example
+16.4k Golang : Send email and SMTP configuration example
+46.2k Golang : Read tab delimited file with encoding/csv package
+26.8k Golang : Convert file content into array of bytes
+6k PHP : How to check if an array is empty ?
+4.7k Adding Skype actions such as call and chat into web page examples
+10.5k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+8.3k Golang : Number guessing game with user input verification example
+22k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."