支持插件热更新修改鉴权API地址

This commit is contained in:
Anthony.Liu
2023-03-21 21:58:05 +08:00
parent 9a30203515
commit c6e3955f6a
3 changed files with 7 additions and 2 deletions

View File

@@ -17,6 +17,8 @@ import (
## 配置
```yaml
#global:
# enableauth: true # 开启鉴权(默认开启)
httpauth:
onsubaddr: http://localhost:9091/subauth
onpubaddr: http://localhost:9091/pubauth

View File

@@ -32,10 +32,12 @@ func (p *HttpAuthConfig) checkAPIOK(addr string, buf []byte) bool {
return true
} else {
if resp, err := http.Post(addr, "application/json", bytes.NewBuffer(buf)); err == nil {
plugin.Info("Auth", zap.String("addr", addr), zap.Int("http_code", resp.StatusCode))
plugin.Info("auth resp", zap.String("addr", addr), zap.Int("http_code", resp.StatusCode))
if resp.StatusCode == http.StatusOK {
return true
}
} else {
plugin.Error("auth req fail", zap.Error(err))
}
}
return false

View File

@@ -20,12 +20,13 @@ type HttpAuthConfig struct {
}
func (p *HttpAuthConfig) OnEvent(event any) {
switch event.(type) {
switch e := event.(type) {
case FirstConfig: //插件初始化逻辑
plugin.Info("Config", zap.String("OnSubAddr", p.OnSubAddr))
plugin.Info("Config", zap.String("OnPubAddr", p.OnPubAddr))
p.changeAuthHook()
case config.Config: //插件热更新逻辑
e.Unmarshal(p)
}
}