Go
文章平均质量分 66
Tanzhiyong97
这个作者很懒,什么都没留下…
展开
-
golang中struct作为func中的参数需要定义为指针类型的原因
为什么golang struct结构体方法中的参数需要定义为指针类型的原因在参考博客中提到的案例:写一个网页的简单计数器问题时防线,计数器居然永远为0,计数器不计数,见鬼了。。。。代码如下:type Counter struct { n int}func (ctr Counter) ServeHTTP(c http.ResponseWriter, req *http.Request) { fmt.Fprintf(c, "%08x\n", ctr) ctr.n++ fmt.Fprintf原创 2021-04-26 11:57:53 · 2062 阅读 · 0 评论 -
Go语言中结构体与JSON映射
常常能见到如下的这样结构体成员后边带有json的标签:type Model struct { ID int `gorm:"primary_key" json:"id"` Del int `json:"del"` //是否删除 CreatedOn time.Time `json:"-"` ModifiedOn time.Time `json:"-"` DeletedAt *time.Time `json:"deleted_at,om转载 2021-04-26 11:41:23 · 1735 阅读 · 0 评论