Skip to content

Commit f8a010a

Browse files
committed
Add delete method
1 parent 7a9642a commit f8a010a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

client.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,41 @@ func (c *Client) UpdateWorkflowDefinition(w WorkflowDefinition) goerror.Error {
270270
return nil
271271
}
272272

273+
func (c *Client) DeleteWorkflowDefinition(name, rev string) goerror.Error {
274+
u, err := url.Parse(fmt.Sprintf("%s/v1/definition/workflow/%s/%s", c.processManagerEndpoint, name, rev))
275+
if err != nil {
276+
return ErrParseRequestBodyFailed.WithCause(err)
277+
}
278+
h := http.Header{}
279+
h.Set("Content-type", "application/json")
280+
281+
resp, err := c.httpClient.Do(&http.Request{
282+
Method: http.MethodDelete,
283+
URL: u,
284+
})
285+
if err != nil {
286+
return ErrRequestFailed.WithCause(err)
287+
}
288+
289+
defer resp.Body.Close()
290+
body, err := ioutil.ReadAll(resp.Body)
291+
if err != nil {
292+
return ErrReadResponseBodyFailed.WithCause(err)
293+
}
294+
295+
var r melonadeResponse
296+
err = json.Unmarshal(body, &r)
297+
if err != nil {
298+
return ErrParseResponseBodyFailed.WithCause(err)
299+
}
300+
301+
if r.Success != true {
302+
return ErrRequestNotSuccess.WithExtendMsg(fmt.Sprintf("%+v", r.Error))
303+
}
304+
305+
return nil
306+
}
307+
273308
func errWithInput(err goerror.Error, workflowName, revision, transactionId string, payload interface{}) goerror.Error {
274309
return err.WithKeyValueInput(
275310
"workflowName", workflowName,

service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ type Service interface {
1717
SetWorkflowDefinition(t WorkflowDefinition) goerror.Error
1818
CreateWorkflowDefinition(t WorkflowDefinition) goerror.Error
1919
UpdateWorkflowDefinition(t WorkflowDefinition) goerror.Error
20+
DeleteWorkflowDefinition(name, rev string) goerror.Error
2021
}

0 commit comments

Comments
 (0)