diff --git a/appconfig/appconfig.go b/appconfig/appconfig.go index 572f77d4..dbdbf028 100644 --- a/appconfig/appconfig.go +++ b/appconfig/appconfig.go @@ -21,7 +21,7 @@ package appconfig import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "strings" @@ -312,7 +312,7 @@ func getLargeFileContents(ctx context.Context, client *github.Client, owner, rep return nil, errors.Errorf("failed to read file: unexpected status code %d", res.StatusCode) } - b, err := ioutil.ReadAll(body) + b, err := io.ReadAll(body) if err != nil { return nil, errors.Wrap(err, "failed to read file") } diff --git a/appconfig/responseplayer_test.go b/appconfig/responseplayer_test.go index fc043b7c..290a924f 100644 --- a/appconfig/responseplayer_test.go +++ b/appconfig/responseplayer_test.go @@ -18,8 +18,9 @@ import ( "bytes" "encoding/base64" "fmt" - "io/ioutil" + "io" "net/http" + "os" "strings" "github.com/pkg/errors" @@ -52,7 +53,7 @@ func (rp *ResponsePlayer) AddRule(matcher RequestMatcher, file string) *Rule { rule := &Rule{Matcher: matcher} rp.Rules = append(rp.Rules, rule) - d, err := ioutil.ReadFile(file) + d, err := os.ReadFile(file) if err != nil { rule.err = errors.Wrapf(err, "failed to read response file: %s", file) return rule @@ -98,7 +99,7 @@ func (r *SavedResponse) Response(req *http.Request) *http.Response { ProtoMinor: 1, Header: header, - Body: ioutil.NopCloser(bytes.NewReader(body)), + Body: io.NopCloser(bytes.NewReader(body)), ContentLength: int64(len(body)), Request: req, @@ -108,7 +109,7 @@ func (r *SavedResponse) Response(req *http.Request) *http.Response { func (rp *ResponsePlayer) findMatch(req *http.Request) *Rule { var body []byte if req.Body != nil { - body, _ = ioutil.ReadAll(req.Body) + body, _ = io.ReadAll(req.Body) _ = req.Body.Close() } @@ -153,7 +154,7 @@ func errorResponse(req *http.Request, code int, msg string) (*http.Response, err ProtoMinor: 1, Header: make(http.Header), - Body: ioutil.NopCloser(body), + Body: io.NopCloser(body), ContentLength: body.Size(), Request: req, diff --git a/example/config.go b/example/config.go index 7fb01f12..7a30007a 100644 --- a/example/config.go +++ b/example/config.go @@ -15,7 +15,7 @@ package main import ( - "io/ioutil" + "os" "github.com/palantir/go-githubapp/githubapp" "github.com/pkg/errors" @@ -41,7 +41,7 @@ type MyApplicationConfig struct { func ReadConfig(path string) (*Config, error) { var c Config - bytes, err := ioutil.ReadFile(path) + bytes, err := os.ReadFile(path) if err != nil { return nil, errors.Wrapf(err, "failed reading server config file: %s", path) } diff --git a/githubapp/context_test.go b/githubapp/context_test.go index 35256ae2..7429402a 100644 --- a/githubapp/context_test.go +++ b/githubapp/context_test.go @@ -31,9 +31,9 @@ func TestPrepareRepoContext(t *testing.T) { ctx := logger.WithContext(context.Background()) _, logger = PrepareRepoContext(ctx, 42, &github.Repository{ - Name: github.String("test"), + Name: github.Ptr("test"), Owner: &github.User{ - Login: github.String("mhaypenny"), + Login: github.Ptr("mhaypenny"), }, }) @@ -60,9 +60,9 @@ func TestPreparePRContext(t *testing.T) { ctx := logger.WithContext(context.Background()) _, logger = PreparePRContext(ctx, 42, &github.Repository{ - Name: github.String("test"), + Name: github.Ptr("test"), Owner: &github.User{ - Login: github.String("mhaypenny"), + Login: github.Ptr("mhaypenny"), }, }, 128) @@ -84,7 +84,7 @@ func TestPreparePRContext(t *testing.T) { assertField(t, "pull request number", 128, entry.Number) } -func assertField(t *testing.T, name string, expected, actual interface{}) { +func assertField(t *testing.T, name string, expected, actual any) { if expected != actual { t.Errorf("incorrect %s: expected %#v (%T), but was %#v (%T)", name, expected, expected, actual, actual) } diff --git a/githubapp/dispatcher_test.go b/githubapp/dispatcher_test.go index 39e524ef..c2371679 100644 --- a/githubapp/dispatcher_test.go +++ b/githubapp/dispatcher_test.go @@ -192,7 +192,7 @@ func TestSetAndGetResponder(t *testing.T) { } func newHookRequest(eventType, id string, signed bool) *http.Request { - body := []byte(fmt.Sprintf(`{"type":"%s"}`, eventType)) + body := fmt.Appendf(nil, `{"type":"%s"}`, eventType) req := httptest.NewRequest(http.MethodPost, "/api/github/hook", bytes.NewReader(body)) req.Header.Set("Content-Type", "application/json") diff --git a/githubapp/errors.go b/githubapp/errors.go index f0da5c9f..b57a9e35 100644 --- a/githubapp/errors.go +++ b/githubapp/errors.go @@ -46,12 +46,12 @@ func errorCounter(r metrics.Registry, event string) metrics.Counter { // HandlerPanicError is an error created from a recovered handler panic. type HandlerPanicError struct { - value interface{} + value any stack []runtime.Frame } // Value returns the exact value with which panic() was called. -func (e HandlerPanicError) Value() interface{} { +func (e HandlerPanicError) Value() any { return e.value } diff --git a/githubapp/middleware_logging_test.go b/githubapp/middleware_logging_test.go index db17c9e4..e8553cec 100644 --- a/githubapp/middleware_logging_test.go +++ b/githubapp/middleware_logging_test.go @@ -41,7 +41,7 @@ func TestClientLogging(t *testing.T) { t.Fatalf("unexpected error making request: %v", err) } - assertLogFields(t, out.Bytes(), map[string]interface{}{ + assertLogFields(t, out.Bytes(), map[string]any{ "method": "GET", "status": float64(200), "request_body": "The request", @@ -60,7 +60,7 @@ func TestClientLogging(t *testing.T) { t.Fatalf("unexpected error making request: %v", err) } - assertLogFields(t, out.Bytes(), map[string]interface{}{ + assertLogFields(t, out.Bytes(), map[string]any{ "method": "GET", "status": float64(200), "request_body": missingField, @@ -79,7 +79,7 @@ func TestClientLogging(t *testing.T) { t.Fatalf("unexpected error making request: %v", err) } - assertLogFields(t, out.Bytes(), map[string]interface{}{ + assertLogFields(t, out.Bytes(), map[string]any{ "method": "GET", "status": float64(200), "request_body": "", @@ -98,7 +98,7 @@ func TestClientLogging(t *testing.T) { t.Fatalf("unexpected error making request: %v", err) } - assertLogFields(t, out.Bytes(), map[string]interface{}{ + assertLogFields(t, out.Bytes(), map[string]any{ "method": "GET", "status": float64(200), "response_body": "The response", @@ -117,7 +117,7 @@ func TestClientLogging(t *testing.T) { t.Fatalf("unexpected error making request: %v", err) } - assertLogFields(t, out.Bytes(), map[string]interface{}{ + assertLogFields(t, out.Bytes(), map[string]any{ "method": "GET", "status": float64(200), "response_body": missingField, @@ -187,10 +187,10 @@ func newEmptyRoundTripper() http.RoundTripper { var missingField struct{} -func assertLogFields(t *testing.T, out []byte, expected map[string]interface{}) { +func assertLogFields(t *testing.T, out []byte, expected map[string]any) { t.Logf("log output: %s", out) - var actual map[string]interface{} + var actual map[string]any if err := json.Unmarshal(out, &actual); err != nil { t.Fatalf("unexpected error unmarshalling log fields: %v", err) } diff --git a/githubapp/scheduler.go b/githubapp/scheduler.go index 8cd0bb43..d793a96b 100644 --- a/githubapp/scheduler.go +++ b/githubapp/scheduler.go @@ -212,7 +212,7 @@ func QueueAsyncScheduler(queueSize int, workers int, opts ...SchedulerOption) Sc opt(&s.scheduler) } - for i := 0; i < workers; i++ { + for range workers { go func() { for d := range s.queue { if s.eventAge != nil {