Swag: Panic on parsing

Created on 10 Apr 2019  路  2Comments  路  Source: swaggo/swag

Describe the bug
A clear and concise description of what the bug is.

It panics when I use swag i

type Param struct {
    SendTime Time `json:"send_time" form:"send_time" gorm:"DEFAULT:NULL"`
}

// Time ...
type Time time.Time

// TimeLayout ...
var TimeLayout = "2006-01-02 15:04:05"

// MarshalJSON ...
func (t Time) MarshalJSON() ([]byte, error) {
    return json.Marshal(time.Time(t).Format(TimeLayout))
}

// UnmarshalJSON ...
func (t *Time) UnmarshalJSON(b []byte) error {
    var s string
    if err := json.Unmarshal(b, &s); err != nil {
        return err
    }

    if s == "" {
        return nil
    }

    tt, err := time.Parse(TimeLayout, s)
    if err != nil {
        return err
    }
    *t = Time(tt)
    return nil
}

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
WechatIMG294

Your swag version
swag version v1.5.0

Your go version
go version 1.11.5

Desktop (please complete the following information):
Macos 10.14.4

Additional context
Add any other context about the problem here.

question

Most helpful comment

please see https://github.com/swaggo/swag#use-swaggertype-tag-to-supported-custom-type, thanks.

All 2 comments

please see https://github.com/swaggo/swag#use-swaggertype-tag-to-supported-custom-type, thanks.

please see https://github.com/swaggo/swag#use-swaggertype-tag-to-supported-custom-type, thanks.

Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chiragg6 picture chiragg6  路  7Comments

wingsofovnia picture wingsofovnia  路  3Comments

Ashtonian picture Ashtonian  路  6Comments

dmirubtsov picture dmirubtsov  路  7Comments

fannheyward picture fannheyward  路  3Comments