Structs can be printed using the builtin print methods as they take advantage of the reflect package.
Print a struct as is with %v
Print a struct with field names by %+v
Run the code here : http://play.golang.org/p/X8ke-0zPUT
Structs can be printed using the builtin print methods as they take advantage of the reflect package.
Print a struct as is with %v
Print a struct with field names by %+v
Run the code here : http://play.golang.org/p/X8ke-0zPUT
package main | |
import "fmt" | |
import "time" | |
type Metric struct { | |
Name string | |
DateTime time.Time | |
Value int | |
} | |
func main() { | |
met := Metric{"Tom",time.Now(),24} | |
fmt.Println(met) | |
fmt.Printf("%+v \n", met) | |
} |