mirror of
https://github.com/haowanxing/plugin-http-auth.git
synced 2025-12-24 10:30:58 +08:00
支持插件热更新修改鉴权API地址
This commit is contained in:
@@ -17,6 +17,8 @@ import (
|
||||
## 配置
|
||||
|
||||
```yaml
|
||||
#global:
|
||||
# enableauth: true # 开启鉴权(默认开启)
|
||||
httpauth:
|
||||
onsubaddr: http://localhost:9091/subauth
|
||||
onpubaddr: http://localhost:9091/pubauth
|
||||
|
||||
4
auth.go
4
auth.go
@@ -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
|
||||
|
||||
3
main.go
3
main.go
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user