Skip to content

Commit

Permalink
refactoring using staticcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
catatsuy committed Jan 14, 2024
1 parent c4e0361 commit 068bd08
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 26 deletions.
5 changes: 0 additions & 5 deletions bench/fails/fails.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const (
ErrApplication failure.StringCode = "error application"
// ErrTimeout はタイムアウトエラー。基本は大目に見る。
ErrTimeout failure.StringCode = "error timeout"
// ErrTemporary は一時的なエラー。基本は大目に見る。
ErrTemporary failure.StringCode = "error temporary"
)

var (
Expand Down Expand Up @@ -82,9 +80,6 @@ func (e *Errors) Add(err error) {
case ErrTimeout:
msg += "(タイムアウトしました)"
e.trivial++
case ErrTemporary:
msg += "(一時的なエラー)"
e.trivial++
case ErrApplication:
e.application++
default:
Expand Down
2 changes: 0 additions & 2 deletions bench/server/shipment.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ func (c *shipmentStore) Get(key string) (shipment, bool) {
}

func init() {
rand.Seed(time.Now().UnixNano())

shipmentHash = sha1.New()
shipmentHash.Write(SecretSeed)
}
Expand Down
7 changes: 2 additions & 5 deletions bench/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package session
import (
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -150,7 +149,7 @@ func checkStatusCode(res *http.Response, expectedStatusCode int) error {
prefixMsg := fmt.Sprintf("%s %s", res.Request.Method, res.Request.URL.Path)

if res.StatusCode != expectedStatusCode {
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
return failure.Wrap(err, failure.Message(prefixMsg+": bodyの読み込みに失敗しました"))
}
Expand All @@ -166,7 +165,7 @@ func checkStatusCodeWithMsg(res *http.Response, expectedStatusCode int, msg stri
prefixMsg := fmt.Sprintf("%s %s", res.Request.Method, res.Request.URL.Path)

if res.StatusCode != expectedStatusCode {
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
return failure.Wrap(err, failure.Message(prefixMsg+": bodyの読み込みに失敗しました "+msg))
}
Expand All @@ -184,8 +183,6 @@ func (s *Session) Do(req *http.Request) (*http.Response, error) {
if nerr, ok := err.(net.Error); ok {
if nerr.Timeout() {
return nil, failure.Translate(err, fails.ErrTimeout)
} else if nerr.Temporary() {
return nil, failure.Translate(err, fails.ErrTemporary)
}
}

Expand Down
5 changes: 2 additions & 3 deletions bench/session/webapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/url"
Expand Down Expand Up @@ -509,7 +508,7 @@ func (s *Session) ShipDone(ctx context.Context, itemID int64) error {
return err
}

_, err = ioutil.ReadAll(res.Body)
_, err = io.ReadAll(res.Body)
if err != nil {
return failure.Wrap(err, failure.Messagef("POST /ship_done: bodyの読み込みに失敗しました (item_id: %d)", itemID))
}
Expand Down Expand Up @@ -540,7 +539,7 @@ func (s *Session) Complete(ctx context.Context, itemID int64) error {
return err
}

_, err = ioutil.ReadAll(res.Body)
_, err = io.ReadAll(res.Body)
if err != nil {
return failure.Wrap(err, failure.Messagef("POST /complete: bodyの読み込みに失敗しました (item_id: %d)", itemID))
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/bench-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ func runBenchmarker(benchmarkerPath string, job *Job) (*BenchmarkResult, error)
fmt.Sprintf("-shipment-url=https://%s", fmt.Sprintf("shipment%s.isucon9q.catatsuy.org", suffix)),
fmt.Sprintf("-target-url=https://%s", target.GlobalIP),
fmt.Sprintf("-allowed-ips=%s", strings.Join(allowedIPs, ",")),
fmt.Sprintf("-data-dir=/home/isucon/isucari/initial-data"),
fmt.Sprintf("-static-dir=/home/isucon/isucari/webapp/public/static"))
"-data-dir=/home/isucon/isucari/initial-data",
"-static-dir=/home/isucon/isucari/webapp/public/static",
)

var (
stdout bytes.Buffer
Expand Down
3 changes: 0 additions & 3 deletions cmd/bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"flag"
"log"
"math/rand"
"net"
"os"
"sort"
Expand Down Expand Up @@ -39,8 +38,6 @@ type Config struct {
}

func init() {
rand.Seed(time.Now().UnixNano())

log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
}

Expand Down
12 changes: 6 additions & 6 deletions webapp/go/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
)

Expand Down Expand Up @@ -68,7 +68,7 @@ func APIPaymentToken(paymentURL string, param *APIPaymentServiceTokenReq) (*APIP
defer res.Body.Close()

if res.StatusCode != http.StatusOK {
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("failed to read res.Body and the status code of the response from shipment service was not 200: %v", err)
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func APIShipmentCreate(shipmentURL string, param *APIShipmentCreateReq) (*APIShi
defer res.Body.Close()

if res.StatusCode != http.StatusOK {
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("failed to read res.Body and the status code of the response from shipment service was not 200: %v", err)
}
Expand Down Expand Up @@ -138,14 +138,14 @@ func APIShipmentRequest(shipmentURL string, param *APIShipmentRequestReq) ([]byt
defer res.Body.Close()

if res.StatusCode != http.StatusOK {
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("failed to read res.Body and the status code of the response from shipment service was not 200: %v", err)
}
return nil, fmt.Errorf("status code: %d; body: %s", res.StatusCode, b)
}

return ioutil.ReadAll(res.Body)
return io.ReadAll(res.Body)
}

func APIShipmentStatus(shipmentURL string, param *APIShipmentStatusReq) (*APIShipmentStatusRes, error) {
Expand All @@ -167,7 +167,7 @@ func APIShipmentStatus(shipmentURL string, param *APIShipmentStatusReq) (*APIShi
defer res.Body.Close()

if res.StatusCode != http.StatusOK {
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("failed to read res.Body and the status code of the response from shipment service was not 200: %v", err)
}
Expand Down

0 comments on commit 068bd08

Please sign in to comment.