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
client := coach_client.NewClient(pool)
productCtl := product.NewController(client, db, cfg.Product)
productCtl := product.NewController(client, db)
//r := fiber.New()
//r.Use(cors.New())

View File

@ -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"
@ -11,7 +10,6 @@ import (
type Config struct {
DB database.DBOption `yaml:"db"`
Proxy proxy.Option `yaml:"proxy"`
Product product.Option `yaml:"product"`
}
func LoadConfig() (*Config, error) {

View File

@ -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) {

View File

@ -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})
}