From c6e3955f6a0cf30d473d38af550ae2d9caa58ae5 Mon Sep 17 00:00:00 2001 From: "Anthony.Liu" Date: Tue, 21 Mar 2023 21:58:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8F=92=E4=BB=B6=E7=83=AD?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BF=AE=E6=94=B9=E9=89=B4=E6=9D=83API?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.MD | 2 ++ auth.go | 4 +++- main.go | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.MD b/README.MD index df9c4c6..a28135b 100644 --- a/README.MD +++ b/README.MD @@ -17,6 +17,8 @@ import ( ## 配置 ```yaml +#global: +# enableauth: true # 开启鉴权(默认开启) httpauth: onsubaddr: http://localhost:9091/subauth onpubaddr: http://localhost:9091/pubauth diff --git a/auth.go b/auth.go index 44a868f..833177a 100644 --- a/auth.go +++ b/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 diff --git a/main.go b/main.go index 102cd38..55ce943 100644 --- a/main.go +++ b/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) } }