Created
April 28, 2022 20:25
-
-
Save jwhonce/9b05720c1152eeeac99d4e90a9dfa77b to your computer and use it in GitHub Desktop.
Using json.RawMessage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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