fix: using validators to validate a map

This commit is contained in:
Yeuoly
2024-09-26 14:48:53 +08:00
parent 68af1ad0e0
commit dd67f65a04
3 changed files with 11 additions and 3 deletions
@@ -76,7 +76,9 @@ func TestInvokeEncrypt(t *testing.T) {
http_invoked = true
ctx.JSON(http.StatusOK, gin.H{
"key": "encrypted",
"data": map[string]any{
"key": "encrypted",
},
})
})
@@ -11,6 +11,7 @@ import (
"github.com/langgenius/dify-plugin-daemon/internal/utils/stream"
)
// Send a request to dify inner api and validate the response
func Request[T any](i *RealBackwardsInvocation, method string, path string, options ...http_requests.HttpOptions) (*T, error) {
options = append(options,
http_requests.HttpHeader(map[string]string{
@@ -89,10 +90,10 @@ func (i *RealBackwardsInvocation) InvokeEncrypt(payload *dify_invocation.InvokeE
return payload.Data, nil
}
data, err := Request[map[string]any](i, "POST", "invoke/encrypt", http_requests.HttpPayloadJson(payload))
data, err := Request[dify_invocation.InvokeEncryptionResponse](i, "POST", "invoke/encrypt", http_requests.HttpPayloadJson(payload))
if err != nil {
return nil, err
}
return *data, nil
return data.Data, nil
}
+5
View File
@@ -212,3 +212,8 @@ type InvokeNodeResponse struct {
Outputs map[string]any `json:"outputs" validate:"required"`
Inputs map[string]any `json:"inputs" validate:"required"`
}
type InvokeEncryptionResponse struct {
Error string `json:"error"`
Data map[string]any `json:"data" validate:"required"`
}