From 455c85f1650d46a4e80027593243ff9483c1bae4 Mon Sep 17 00:00:00 2001 From: cdle <798731886@qq.com> Date: Tue, 21 Sep 2021 12:19:51 +0800 Subject: [PATCH] update --- core/reply.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/core/reply.go b/core/reply.go index e9cc3b4..10bd7f8 100644 --- a/core/reply.go +++ b/core/reply.go @@ -3,6 +3,7 @@ package core import ( "fmt" "io/ioutil" + "regexp" "strings" "github.com/beego/beego/v2/adapter/httplib" @@ -20,6 +21,7 @@ type Reply struct { Headers []string ResponseType string `yaml:"response_type"` //text json image Get string + Regex string } } @@ -70,12 +72,20 @@ func InitReplies() { f, err := jsonparser.GetString(d, strings.Split(reply.Request.Get, ".")...) if err != nil { s.Reply(err) - return true + return nil } s.Reply(httplib.Get(f).Response()) - } else { - s.Reply(rsp) + return nil } + if reply.Request.Regex != "" { + d, _ := ioutil.ReadAll(rsp.Body) + res := regexp.MustCompile(reply.Request.Regex).FindStringSubmatch(string(d)) + if len(res) != 0 { + s.Reply(httplib.Get(res[1]).Response()) + } + return nil + } + s.Reply(rsp) case "json": d, _ := ioutil.ReadAll(rsp.Body) f, err := jsonparser.GetString(d, strings.Split(reply.Request.Get, ".")...)