1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-23 20:47:03 +00:00

rest: resolve linter errors (#430)

This commit is contained in:
James Hillyerd
2023-11-12 19:32:43 -08:00
committed by GitHub
parent 86d762ac88
commit 7ae7d29741
6 changed files with 42 additions and 54 deletions

View File

@@ -1,12 +1,13 @@
package client_test
import (
"github.com/gorilla/mux"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/gorilla/mux"
"github.com/inbucket/inbucket/v3/pkg/rest/client"
)
@@ -357,5 +358,5 @@ type jsonHandler struct {
func (j *jsonHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
j.called = true
w.Write([]byte(j.json))
_, _ = w.Write([]byte(j.json))
}

View File

@@ -62,7 +62,7 @@ func exampleSetup() (baseURL string, teardown func()) {
// Handle ListMailbox request.
router.HandleFunc("/api/v1/mailbox/user1", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`[
_, _ = w.Write([]byte(`[
{
"mailbox": "user1",
"id": "20180107T224128-0000",
@@ -79,7 +79,7 @@ func exampleSetup() (baseURL string, teardown func()) {
// Handle GetMessage request.
router.HandleFunc("/api/v1/mailbox/user1/20180107T224128-0000",
func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{
_, _ = w.Write([]byte(`{
"mailbox": "user1",
"id": "20180107T224128-0000",
"from": "admin@inbucket.org",

View File

@@ -58,24 +58,3 @@ func (c *restClient) doJSON(method string, uri string, v interface{}) error {
return fmt.Errorf("%s for %q, unexpected %v: %s", method, uri, resp.StatusCode, resp.Status)
}
// doJSONBody performs an HTTP request with this client and marshalls the JSON response into v.
func (c *restClient) doJSONBody(method string, uri string, body []byte, v interface{}) error {
resp, err := c.do(method, uri, body)
if err != nil {
return err
}
defer func() {
_ = resp.Body.Close()
}()
if resp.StatusCode == http.StatusOK {
if v == nil {
return nil
}
// Decode response body
return json.NewDecoder(resp.Body).Decode(v)
}
return fmt.Errorf("%s for %q, unexpected %v: %s", method, uri, resp.StatusCode, resp.Status)
}