Tag:Go uses omitempty

  • Code examples using omitempty in go

    Time:2019-8-21

    Omitempty in go Code directly: package main import ( “encoding/json” “fmt” ) type Person struct { Name string `json:”name”` Age int `json:”age”` Addr string `json:”addr,omitempty”` } func main() { p1 := Person{ Name: “taoge”, Age: 30, } data, err := json.Marshal(p1) if err != nil { panic(err) } fmt.Printf(“%s\n”, data) fmt.Println(p1.Name, p1.Age, p1.Addr) p2 := […]