I recommend to use the Pretty Printer Library. With it, you can print any Go struct very easily.
package main
import (
"fmt"
"github.com/kr/pretty"
)
func main() {
type Data []byte
type Commits []string
type Project struct {
Id int64 `json:"project_id"`
Title string `json:"title"`
Name string `json:"name"`
Data Data `json:"data"`
Commits Commits `json:"commits"`
}
myProject := Project{
Id: 111672727,
Title: "My awesome project!",
Name: "To demo how `pretty` works",
Data: []byte("will work"),
Commits: []string{"one commit", "two commits", "three commits"},
}
fmt.Printf("%# v\n", pretty.Formatter(myProject)) // It will print all struct details
fmt.Printf("%# v\n", pretty.Formatter(myProject.Id)) // It will print component one by one.
}
Output
main.Project{
Id: 111672727,
Title: "My awesome project!",
Name: "To demo how `pretty` works",
Data: {0x77, 0x69, 0x6c, 0x6c, 0x20, 0x77, 0x6f, 0x72, 0x6b},
Commits: {"one commit", "two commits", "three commits"},
}
int64(111672727)
See the example above running on the Go Playground.
You can also get the difference between component through this library among several other things. Have a look at the library Docs.