From 8934e23bd84a48e93c28b1098d891468ee4d9a9c Mon Sep 17 00:00:00 2001 From: timerzz Date: Tue, 14 May 2024 16:17:04 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E9=85=8D=E7=BD=AE=E5=86=99=E5=85=A5?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/main.go | 2 +- pkg/options/init.go | 6 ++---- product/controller.go | 7 ++++--- product/option.go | 5 +++++ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 83504bf..0e52492 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -34,7 +34,7 @@ func main() { // coach client client := coach_client.NewClient(pool) - productCtl := product.NewController(client, db, cfg.Product) + productCtl := product.NewController(client, db) //r := fiber.New() //r.Use(cors.New()) diff --git a/pkg/options/init.go b/pkg/options/init.go index a692755..ccb3865 100644 --- a/pkg/options/init.go +++ b/pkg/options/init.go @@ -1,7 +1,6 @@ package options import ( - "gitea.timerzz.com/kedaya_haitao/coach-spider/product" "gitea.timerzz.com/kedaya_haitao/common/pkg/database" "gitea.timerzz.com/kedaya_haitao/common/pkg/proxy" "gopkg.in/yaml.v3" @@ -9,9 +8,8 @@ import ( ) type Config struct { - DB database.DBOption `yaml:"db"` - Proxy proxy.Option `yaml:"proxy"` - Product product.Option `yaml:"product"` + DB database.DBOption `yaml:"db"` + Proxy proxy.Option `yaml:"proxy"` } func LoadConfig() (*Config, error) { diff --git a/product/controller.go b/product/controller.go index a0de524..cdf58df 100644 --- a/product/controller.go +++ b/product/controller.go @@ -20,12 +20,13 @@ type Controller struct { Option } -func NewController(client *coach_client.Client, db *gorm.DB, opt Option) *Controller { - return &Controller{ +func NewController(client *coach_client.Client, db *gorm.DB) *Controller { + ctl := &Controller{ client: client, db: db, - Option: opt, } + ctl.LoadOption() + return ctl } func (c *Controller) Run(ctx context.Context) { diff --git a/product/option.go b/product/option.go index 7a28d1c..4d8646d 100644 --- a/product/option.go +++ b/product/option.go @@ -3,7 +3,12 @@ package product import "time" type Option struct { + ID uint `gorm:"primary_key" json:"id"` Interval time.Duration `yaml:"interval"` ExchangeRate float64 `yaml:"exchangeRate"` //汇率 Freight float64 `yaml:"freight"` //运费 } + +func (c *Controller) LoadOption() { + c.db.FirstOrCreate(&c.Option, Option{Interval: time.Hour * 30, ExchangeRate: 7.3, Freight: 100}) +}