us-coach-spider/server/spider.go
timerzz 9a916cc85e
Some checks failed
Build image / build (push) Failing after 1m51s
feat 添加修改spider 配置的方式
2024-05-14 21:18:24 +08:00

36 lines
680 B
Go

package server
import (
"gitea.timerzz.com/kedaya_haitao/coach-spider/product"
"github.com/gofiber/fiber/v3"
)
type SpiderSvc struct {
ctl *product.Controller
}
func NewSpiderSvc(ctl *product.Controller) *SpiderSvc {
return &SpiderSvc{
ctl: ctl,
}
}
func (s *SpiderSvc) RegistryRouter(r fiber.Router) {
r.Get("spider/cfg", s.GetSpiderCfg)
r.Post("spider/cfg", s.SetSpiderCfg)
}
func (s *SpiderSvc) GetSpiderCfg(ctx fiber.Ctx) error {
opt := s.ctl.GetOption()
return ctx.JSON(&opt)
}
func (s *SpiderSvc) SetSpiderCfg(ctx fiber.Ctx) error {
var opt product.Option
if err := ctx.Bind().JSON(&opt); err != nil {
return err
}
s.ctl.SaveOption(opt)
return nil
}