From 04c0d4a4ec515e6f6e3d7f0b9dd729c0ff7c66d6 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Fri, 28 Jun 2024 20:19:27 +0900 Subject: [PATCH] go fmt ./... --- uploads.go | 106 ++++++++++++++++++++++++++--------------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/uploads.go b/uploads.go index a51b613..16b8b07 100644 --- a/uploads.go +++ b/uploads.go @@ -1,53 +1,53 @@ -package redmine - -import ( - "bytes" - "encoding/json" - "errors" - "io/ioutil" - "net/http" - "strings" -) - -type uploadResponse struct { - Upload Upload `json:"upload"` -} - -type Upload struct { - Token string `json:"token"` - Filename string `json:"filename"` - ContentType string `json:"content_type"` -} - -func (c *Client) Upload(filename string) (*Upload, error) { - content, err := ioutil.ReadFile(filename) - if err != nil { - return nil, err - } - req, err := http.NewRequest("POST", c.endpoint+"/uploads.json?key="+c.apikey, bytes.NewBuffer(content)) - if err != nil { - return nil, err - } - req.Header.Set("Content-Type", "application/octet-stream") - res, err := c.Do(req) - if err != nil { - return nil, err - } - defer res.Body.Close() - - decoder := json.NewDecoder(res.Body) - var r uploadResponse - if res.StatusCode != 201 { - var er errorsResult - err = decoder.Decode(&er) - if err == nil { - err = errors.New(strings.Join(er.Errors, "\n")) - } - } else { - err = decoder.Decode(&r) - } - if err != nil { - return nil, err - } - return &r.Upload, nil -} +package redmine + +import ( + "bytes" + "encoding/json" + "errors" + "io/ioutil" + "net/http" + "strings" +) + +type uploadResponse struct { + Upload Upload `json:"upload"` +} + +type Upload struct { + Token string `json:"token"` + Filename string `json:"filename"` + ContentType string `json:"content_type"` +} + +func (c *Client) Upload(filename string) (*Upload, error) { + content, err := ioutil.ReadFile(filename) + if err != nil { + return nil, err + } + req, err := http.NewRequest("POST", c.endpoint+"/uploads.json?key="+c.apikey, bytes.NewBuffer(content)) + if err != nil { + return nil, err + } + req.Header.Set("Content-Type", "application/octet-stream") + res, err := c.Do(req) + if err != nil { + return nil, err + } + defer res.Body.Close() + + decoder := json.NewDecoder(res.Body) + var r uploadResponse + if res.StatusCode != 201 { + var er errorsResult + err = decoder.Decode(&er) + if err == nil { + err = errors.New(strings.Join(er.Errors, "\n")) + } + } else { + err = decoder.Decode(&r) + } + if err != nil { + return nil, err + } + return &r.Upload, nil +}