Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Struct Printing

Struct Printing

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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.