feat: 支持请求中独立的 Path 字段

Signed-off-by: Ke Jie <chzealot@gmail.com>
This commit is contained in:
Ke Jie 2024-06-11 20:12:14 +08:00
parent f92294fda9
commit 5f78647a9a
3 changed files with 9 additions and 1 deletions

View File

@ -41,7 +41,7 @@ type UserAgentConfig struct {
func NewDingtalkGoSDKUserAgent() *UserAgentConfig { func NewDingtalkGoSDKUserAgent() *UserAgentConfig {
return &UserAgentConfig{ return &UserAgentConfig{
UserAgent: "dingtalk-sdk-go/v0.8.0", UserAgent: "dingtalk-sdk-go/v0.9.0",
} }
} }

View File

@ -7,6 +7,7 @@ import (
type GraphRequestLine struct { type GraphRequestLine struct {
Method string `json:"method"` Method string `json:"method"`
Uri string `json:"uri"` Uri string `json:"uri"`
Path string `json:"-"`
} }
type GraphRequest struct { type GraphRequest struct {
RequestLine GraphRequestLine `json:"requestLine"` RequestLine GraphRequestLine `json:"requestLine"`

View File

@ -3,6 +3,7 @@ package plugin
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"strings"
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload" "github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
) )
@ -29,6 +30,12 @@ func (h *DefaultPluginFrameHandler) OnEventReceived(ctx context.Context, df *pay
if err != nil { if err != nil {
return nil, err return nil, err
} }
pos := strings.Index(msgData.RequestLine.Uri, "?")
if pos >= 0 {
msgData.RequestLine.Path = msgData.RequestLine.Uri[:pos]
} else {
msgData.RequestLine.Path = msgData.RequestLine.Uri
}
if h.defaultHandler == nil { if h.defaultHandler == nil {
return payload.NewDataFrameResponse(payload.DataFrameResponseStatusCodeKHandlerNotFound), nil return payload.NewDataFrameResponse(payload.DataFrameResponseStatusCodeKHandlerNotFound), nil