| 120 | } |
| 121 | |
| 122 | func getReq(ctx context.DnoteCtx, path, method, body string) (*http.Request, error) { |
| 123 | endpoint := fmt.Sprintf("%s%s", ctx.APIEndpoint, path) |
| 124 | req, err := http.NewRequest(method, endpoint, strings.NewReader(body)) |
| 125 | if err != nil { |
| 126 | return nil, errors.Wrap(err, "constructing http request") |
| 127 | } |
| 128 | |
| 129 | req.Header.Set("CLI-Version", ctx.Version) |
| 130 | |
| 131 | if ctx.SessionKey != "" { |
| 132 | credential := fmt.Sprintf("Bearer %s", ctx.SessionKey) |
| 133 | req.Header.Set("Authorization", credential) |
| 134 | } |
| 135 | |
| 136 | return req, nil |
| 137 | } |
| 138 | |
| 139 | // checkRespErr checks if the given http response indicates an error. It returns a boolean indicating |
| 140 | // if the response is an error, and a decoded error message. |