Skip to content

Instantly share code, notes, and snippets.

@jwhonce
Created April 28, 2022 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwhonce/9b05720c1152eeeac99d4e90a9dfa77b to your computer and use it in GitHub Desktop.
Save jwhonce/9b05720c1152eeeac99d4e90a9dfa77b to your computer and use it in GitHub Desktop.
Using json.RawMessage
// Remove deletes a Pod from local storage. The optional force parameter denotes
// that the Pod can be removed even if in a running state.
func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) (*entities.PodRmReport, error) {
conn, err := bindings.GetClient(ctx)
if err != nil {
return nil, err
}
var params url.Values
if options != nil {
var err error
if params, err = options.ToParams(); err != nil {
return nil, err
}
}
response, err := conn.DoRequest(ctx, nil, http.MethodDelete, "/pods/%s", params, nil, nameOrID)
if err != nil {
return nil, err
}
defer response.Body.Close()
var report entities.PodRmReport
if response.IsSuccess() || response.IsRedirection() {
body := struct {
Id string
Err *json.RawMessage
}{}
data, _ := io.ReadAll(response.Body)
_ = json.Unmarshal(data, &body)
if body.Err != nil {
var msg string
_ = json.Unmarshal(*body.Err, &msg)
report.Err = errors.New(msg)
}
return &report, nil
}
// fallthrough to process StatusCode >= 400
return &report, response.Process(&report)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment