mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-04 19:17:37 +08:00
feat(http): accept onebot v12 style endpoint
disabled currently, enabled in v1.1.0
This commit is contained in:
parent
19fd331c46
commit
446f624a37
@ -29,3 +29,9 @@ var (
|
||||
func nocheck(_ io.ReadSeeker) (bool, string) {
|
||||
return true, ""
|
||||
}
|
||||
|
||||
// todo: enable in v1.1.0
|
||||
// onebot v12 feature
|
||||
const (
|
||||
AcceptOneBotV12HTTPEndPoint = false
|
||||
)
|
||||
|
@ -22,6 +22,8 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/Mrs4s/go-cqhttp/coolq"
|
||||
"github.com/Mrs4s/go-cqhttp/global"
|
||||
"github.com/Mrs4s/go-cqhttp/internal/base"
|
||||
"github.com/Mrs4s/go-cqhttp/modules/config"
|
||||
)
|
||||
|
||||
@ -115,14 +117,21 @@ func (s *httpServer) ServeHTTP(writer http.ResponseWriter, request *http.Request
|
||||
return
|
||||
}
|
||||
|
||||
var response global.MSG
|
||||
if base.AcceptOneBotV12HTTPEndPoint && request.URL.Path == "/" {
|
||||
action := strings.TrimSuffix(ctx.Get("action").Str, "_async")
|
||||
log.Debugf("HTTPServer接收到API调用: %v", action)
|
||||
response = s.api.callAPI(action, ctx.Get("params"))
|
||||
} else {
|
||||
action := strings.TrimPrefix(request.URL.Path, "/")
|
||||
action = strings.TrimSuffix(action, "_async")
|
||||
log.Debugf("HTTPServer接收到API调用: %v", action)
|
||||
ret := s.api.callAPI(action, &ctx)
|
||||
response = s.api.callAPI(action, &ctx)
|
||||
}
|
||||
|
||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
writer.WriteHeader(http.StatusOK)
|
||||
_ = json.NewEncoder(writer).Encode(ret)
|
||||
_ = json.NewEncoder(writer).Encode(response)
|
||||
}
|
||||
|
||||
func checkAuth(req *http.Request, token string) int {
|
||||
|
Loading…
x
Reference in New Issue
Block a user