package product import "time" type Option struct { ID uint `gorm:"primary_key" json:"id"` Interval time.Duration `yaml:"interval" json:"interval"` ExchangeRate float64 `yaml:"exchangeRate" json:"exchangeRate"` //汇率 Freight float64 `yaml:"freight" json:"freight"` //运费 } func (c *Controller) LoadOption() { c.db.FirstOrCreate(&c.Option, Option{Interval: time.Hour * 30, ExchangeRate: 7.3, Freight: 100}) } func (c *Controller) SaveOption(opt Option) { if opt.Interval > 0 { c.Option.Interval = opt.Interval } if opt.ExchangeRate > 0 { c.Option.ExchangeRate = opt.ExchangeRate } if opt.Freight > 0 { c.Option.Freight = opt.Freight } opt.ID = 1 c.db.Updates(opt) } func (c *Controller) GetOption() Option { return c.Option }