Assigning null to JSON fields instead of empty strings

后端 未结 5 1905
迷失自我
迷失自我 2020-11-29 23:34

Since empty string is the zero/default value for Go string, I decided to define all such fields as interface{} instead. for example



        
5条回答
  •  时光说笑
    2020-11-30 00:15

    Can be used https://github.com/guregu/null

    type student struct {
    FirstName  null.String `json:"first_name"`
    MiddleName null.String `json:"middle_name"`
    LastName   null.String `json:"last_name"`}
    

提交回复
热议问题