Browse Source

添加方法

yjp19871013@126.com 2 years ago
parent
commit
5c6a7a9ef7
1 changed files with 15 additions and 0 deletions
  1. 15 0
      client.go

+ 15 - 0
client.go

@@ -53,6 +53,10 @@ func (client *Client) InvokePostMethodJson(appID string, methodName string, json
 	return client.invokeMethodJson(appID, methodName, "post", jsonData)
 }
 
+func (client *Client) InvokePostMethodMultipart(appID string, methodName string, data []byte) ([]byte, error) {
+	return client.invokeMethodWithContentType(appID, methodName, "post", "multipart/form-data", data)
+}
+
 func (client *Client) InvokePutMethodJson(appID string, methodName string, jsonData []byte) ([]byte, error) {
 	return client.invokeMethodJson(appID, methodName, "put", jsonData)
 }
@@ -86,6 +90,17 @@ func (client *Client) invokeMethodJson(appID string, methodName string, verb str
 		})
 }
 
+func (client *Client) invokeMethodWithContentType(appID string, methodName string, verb string, contentType string, data []byte) ([]byte, error) {
+	ctx, cancel := context.WithTimeout(context.Background(), time.Duration(client.timeoutSec)*time.Second)
+	defer cancel()
+
+	return client.client.InvokeMethodWithContent(ctx, appID, methodName, verb,
+		&dapr.DataContent{
+			Data:        data,
+			ContentType: contentType,
+		})
+}
+
 func (client *Client) SaveState(stateStoreName string, key string, value []byte, meta map[string]string, so ...dapr.StateOption) error {
 	ctx, cancel := context.WithTimeout(context.Background(), time.Duration(client.timeoutSec)*time.Second)
 	defer cancel()