update
This commit is contained in:
+13
-3
@@ -3,6 +3,7 @@ package core
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/httplib"
|
"github.com/beego/beego/v2/adapter/httplib"
|
||||||
@@ -20,6 +21,7 @@ type Reply struct {
|
|||||||
Headers []string
|
Headers []string
|
||||||
ResponseType string `yaml:"response_type"` //text json image
|
ResponseType string `yaml:"response_type"` //text json image
|
||||||
Get string
|
Get string
|
||||||
|
Regex string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,12 +72,20 @@ func InitReplies() {
|
|||||||
f, err := jsonparser.GetString(d, strings.Split(reply.Request.Get, ".")...)
|
f, err := jsonparser.GetString(d, strings.Split(reply.Request.Get, ".")...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.Reply(err)
|
s.Reply(err)
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
s.Reply(httplib.Get(f).Response())
|
s.Reply(httplib.Get(f).Response())
|
||||||
} else {
|
return nil
|
||||||
s.Reply(rsp)
|
|
||||||
}
|
}
|
||||||
|
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":
|
case "json":
|
||||||
d, _ := ioutil.ReadAll(rsp.Body)
|
d, _ := ioutil.ReadAll(rsp.Body)
|
||||||
f, err := jsonparser.GetString(d, strings.Split(reply.Request.Get, ".")...)
|
f, err := jsonparser.GetString(d, strings.Split(reply.Request.Get, ".")...)
|
||||||
|
|||||||
Reference in New Issue
Block a user