36 lines
680 B
Go
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
|
|
}
|