update for strict config (#3779)

This commit is contained in:
fatedier
2023-11-16 21:03:36 +08:00
committed by GitHub
parent e8deb65c4b
commit 526e809bd5
15 changed files with 99 additions and 70 deletions

View File

@@ -45,8 +45,13 @@ func (svr *Service) healthz(w http.ResponseWriter, _ *http.Request) {
}
// GET /api/reload
func (svr *Service) apiReload(w http.ResponseWriter, _ *http.Request) {
func (svr *Service) apiReload(w http.ResponseWriter, r *http.Request) {
res := GeneralResponse{Code: 200}
strictConfigMode := false
strictStr := r.URL.Query().Get("strictConfig")
if strictStr != "" {
strictConfigMode, _ = strconv.ParseBool(strictStr)
}
log.Info("api request [/api/reload]")
defer func() {
@@ -57,7 +62,7 @@ func (svr *Service) apiReload(w http.ResponseWriter, _ *http.Request) {
}
}()
cliCfg, pxyCfgs, visitorCfgs, _, err := config.LoadClientConfig(svr.cfgFile, svr.strictConfig)
cliCfg, pxyCfgs, visitorCfgs, _, err := config.LoadClientConfig(svr.cfgFile, strictConfigMode)
if err != nil {
res.Code = 400
res.Msg = err.Error()

View File

@@ -70,9 +70,6 @@ type Service struct {
// string if no configuration file was used.
cfgFile string
// Whether strict configuration parsing had been requested.
strictConfig bool
// service context
ctx context.Context
// call cancel to stop service
@@ -85,16 +82,14 @@ func NewService(
pxyCfgs []v1.ProxyConfigurer,
visitorCfgs []v1.VisitorConfigurer,
cfgFile string,
strictConfig bool,
) *Service {
return &Service{
authSetter: auth.NewAuthSetter(cfg.Auth),
cfg: cfg,
cfgFile: cfgFile,
strictConfig: strictConfig,
pxyCfgs: pxyCfgs,
visitorCfgs: visitorCfgs,
ctx: context.Background(),
authSetter: auth.NewAuthSetter(cfg.Auth),
cfg: cfg,
cfgFile: cfgFile,
pxyCfgs: pxyCfgs,
visitorCfgs: visitorCfgs,
ctx: context.Background(),
}
}