feat 配置写入数据库
All checks were successful
Build image / build (push) Successful in 1m34s

This commit is contained in:
timerzz 2024-05-14 16:17:04 +08:00
parent ddc538f99b
commit 8934e23bd8
4 changed files with 12 additions and 8 deletions

View File

@ -34,7 +34,7 @@ func main() {
// coach client // coach client
client := coach_client.NewClient(pool) client := coach_client.NewClient(pool)
productCtl := product.NewController(client, db, cfg.Product) productCtl := product.NewController(client, db)
//r := fiber.New() //r := fiber.New()
//r.Use(cors.New()) //r.Use(cors.New())

View File

@ -1,7 +1,6 @@
package options package options
import ( import (
"gitea.timerzz.com/kedaya_haitao/coach-spider/product"
"gitea.timerzz.com/kedaya_haitao/common/pkg/database" "gitea.timerzz.com/kedaya_haitao/common/pkg/database"
"gitea.timerzz.com/kedaya_haitao/common/pkg/proxy" "gitea.timerzz.com/kedaya_haitao/common/pkg/proxy"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
@ -9,9 +8,8 @@ import (
) )
type Config struct { type Config struct {
DB database.DBOption `yaml:"db"` DB database.DBOption `yaml:"db"`
Proxy proxy.Option `yaml:"proxy"` Proxy proxy.Option `yaml:"proxy"`
Product product.Option `yaml:"product"`
} }
func LoadConfig() (*Config, error) { func LoadConfig() (*Config, error) {

View File

@ -20,12 +20,13 @@ type Controller struct {
Option Option
} }
func NewController(client *coach_client.Client, db *gorm.DB, opt Option) *Controller { func NewController(client *coach_client.Client, db *gorm.DB) *Controller {
return &Controller{ ctl := &Controller{
client: client, client: client,
db: db, db: db,
Option: opt,
} }
ctl.LoadOption()
return ctl
} }
func (c *Controller) Run(ctx context.Context) { func (c *Controller) Run(ctx context.Context) {

View File

@ -3,7 +3,12 @@ package product
import "time" import "time"
type Option struct { type Option struct {
ID uint `gorm:"primary_key" json:"id"`
Interval time.Duration `yaml:"interval"` Interval time.Duration `yaml:"interval"`
ExchangeRate float64 `yaml:"exchangeRate"` //汇率 ExchangeRate float64 `yaml:"exchangeRate"` //汇率
Freight float64 `yaml:"freight"` //运费 Freight float64 `yaml:"freight"` //运费
} }
func (c *Controller) LoadOption() {
c.db.FirstOrCreate(&c.Option, Option{Interval: time.Hour * 30, ExchangeRate: 7.3, Freight: 100})
}