refactor: replace bash hacks with custom templates (#34)

This commit is contained in:
Daniel Moran
2021-04-19 15:51:53 -04:00
committed by GitHub
parent 4f62e469e9
commit 079f707c21
9 changed files with 1323 additions and 57 deletions

View File

@ -1,6 +1,3 @@
//lint:file-ignore ST1005 Ignore capitalized errors, they're generated
//lint:file-ignore SA6005 Ignore old-fashioned way of comparing strings, it's generated
/*
* Subset of Influx API covered by Influx CLI
*
@ -104,7 +101,7 @@ func selectHeaderAccept(accepts []string) string {
// contains is a case insenstive match, finding needle in a haystack
func contains(haystack []string, needle string) bool {
for _, a := range haystack {
if strings.ToLower(a) == strings.ToLower(needle) {
if strings.EqualFold(a, needle) {
return true
}
}
@ -120,7 +117,7 @@ func typeCheckParameter(obj interface{}, expected string, name string) error {
// Check the type is as expected.
if reflect.TypeOf(obj).String() != expected {
return fmt.Errorf("Expected %s to be of type %s but received %s.", name, expected, reflect.TypeOf(obj).String())
return fmt.Errorf("expected %s to be of type %s but received %s", name, expected, reflect.TypeOf(obj).String())
}
return nil
}
@ -220,7 +217,7 @@ func (c *APIClient) prepareRequest(
// add form parameters and file if available.
if strings.HasPrefix(headerParams["Content-Type"], "multipart/form-data") && len(formParams) > 0 || (len(fileBytes) > 0 && fileName != "") {
if body != nil {
return nil, errors.New("Cannot specify postBody and multipart form at the same time.")
return nil, errors.New("cannot specify postBody and multipart form at the same time")
}
body = &bytes.Buffer{}
w := multipart.NewWriter(body)
@ -260,7 +257,7 @@ func (c *APIClient) prepareRequest(
if strings.HasPrefix(headerParams["Content-Type"], "application/x-www-form-urlencoded") && len(formParams) > 0 {
if body != nil {
return nil, errors.New("Cannot specify postBody and x-www-form-urlencoded form at the same time.")
return nil, errors.New("cannot specify postBody and x-www-form-urlencoded form at the same time")
}
body = &bytes.Buffer{}
body.WriteString(formParams.Encode())
@ -362,7 +359,7 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
return err
}
} else {
return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined")
return errors.New("unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined")
}
} else if err = json.Unmarshal(b, v); err != nil { // simple model
return err
@ -421,7 +418,7 @@ func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err e
}
if bodyBuf.Len() == 0 {
err = fmt.Errorf("Invalid body type %s\n", contentType)
err = fmt.Errorf("invalid body type %s", contentType)
return nil, err
}
return bodyBuf, nil