dromara / carbon

A simple, semantic and developer-friendly golang package for time
https://pkg.go.dev/github.com/golang-module/carbon/v2
MIT License
4.77k stars 238 forks source link

How to loadTag a slice list? #233

Closed liaohongxing closed 4 months ago

liaohongxing commented 6 months ago
type Person struct {
  Name string `json:"name"`
  Age  int    `json:"age"`

  Field1 carbon.Carbon `json:"field1" carbon:"type:date" tz:"PRC"`
  Field2 carbon.Carbon `json:"field2" carbon:"type:time" tz:"PRC"`
  Field3 carbon.Carbon `json:"field3" carbon:"type:dateTime" tz:"PRC"`
}

list := make([]models.Person, 0)
if err := carbon.LoadTag(&list); err != nil {
    return nil, nil, err
}

将切片传入报错 reflect: call of reflect.Value.NumField on slice Value

gouguoyin commented 6 months ago

v2.3.12 has been released, temporarily use the following instead

type Person struct {
  Name string `json:"name"`
  Age  int    `json:"age"`

  Field1 carbon.Date `json:"field1"`
  Field2 carbon.Time `json:"field2"`
  Field3 carbon.DateTime `json:"field3"`
}