33
// NewCompletionHTTPClient constructs a [CompletionHTTPClient] from given options for sending Nexus operation completion
34
// callbacks via HTTP.
35
>
func NewCompletionHTTPClient(options CompletionHTTPClientOptions) *CompletionHTTPClient {
completion.go
36
>
if options.HTTPCaller == nil {
38
>
}
41
>
}
44
>
}
46
>
baseHTTPClient: baseHTTPClient{
47
>
httpCaller: options.HTTPCaller,
48
>
serializer: options.Serializer,
49
>
failureConverter: options.FailureConverter,
50
>
},
51
>
}
52
}
53
54
// CompleteOperation sends a completion callback for a Nexus operation to the given URL with the given completion details.
55
>
func (c *CompletionHTTPClient) CompleteOperation(ctx context.Context, url string, completion CompleteOperationOptions) error {
completion.go
56
>
httpReq, err := http.NewRequestWithContext(ctx, "POST", url, nil)
57
>
if err != nil {
58
return err
59
}
61
return err
62
}
63
65
>
if err != nil {
66
return err
67
}
68
70
>
// Body is not read but should be discarded to keep the underlying TCP connection alive.
completion.go
71
>
// Just in case something unexpected happens while discarding or closing the body,
72
>
// propagate errors to the machine.
73
>
if _, err = io.Copy(io.Discard, response.Body); err == nil {
74
>
if err = response.Body.Close(); err != nil {
75
return err
76
}
77
}
79
}
80