Skip to content

Instantly share code, notes, and snippets.

@RadioactiveMouse
Created October 25, 2012 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RadioactiveMouse/3952138 to your computer and use it in GitHub Desktop.
Save RadioactiveMouse/3952138 to your computer and use it in GitHub Desktop.
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