Skip to content

Commit 8398181

Browse files
Excavator: Run go fix to apply Go 1.26+ modernizers (#525)
1 parent cb460a1 commit 8398181

8 files changed

Lines changed: 26 additions & 25 deletions

File tree

appconfig/appconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ package appconfig
2121
import (
2222
"context"
2323
"fmt"
24-
"io/ioutil"
24+
"io"
2525
"net/http"
2626
"strings"
2727

@@ -312,7 +312,7 @@ func getLargeFileContents(ctx context.Context, client *github.Client, owner, rep
312312
return nil, errors.Errorf("failed to read file: unexpected status code %d", res.StatusCode)
313313
}
314314

315-
b, err := ioutil.ReadAll(body)
315+
b, err := io.ReadAll(body)
316316
if err != nil {
317317
return nil, errors.Wrap(err, "failed to read file")
318318
}

appconfig/responseplayer_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import (
1818
"bytes"
1919
"encoding/base64"
2020
"fmt"
21-
"io/ioutil"
21+
"io"
2222
"net/http"
23+
"os"
2324
"strings"
2425

2526
"github.com/pkg/errors"
@@ -52,7 +53,7 @@ func (rp *ResponsePlayer) AddRule(matcher RequestMatcher, file string) *Rule {
5253
rule := &Rule{Matcher: matcher}
5354
rp.Rules = append(rp.Rules, rule)
5455

55-
d, err := ioutil.ReadFile(file)
56+
d, err := os.ReadFile(file)
5657
if err != nil {
5758
rule.err = errors.Wrapf(err, "failed to read response file: %s", file)
5859
return rule
@@ -98,7 +99,7 @@ func (r *SavedResponse) Response(req *http.Request) *http.Response {
9899
ProtoMinor: 1,
99100

100101
Header: header,
101-
Body: ioutil.NopCloser(bytes.NewReader(body)),
102+
Body: io.NopCloser(bytes.NewReader(body)),
102103
ContentLength: int64(len(body)),
103104

104105
Request: req,
@@ -108,7 +109,7 @@ func (r *SavedResponse) Response(req *http.Request) *http.Response {
108109
func (rp *ResponsePlayer) findMatch(req *http.Request) *Rule {
109110
var body []byte
110111
if req.Body != nil {
111-
body, _ = ioutil.ReadAll(req.Body)
112+
body, _ = io.ReadAll(req.Body)
112113
_ = req.Body.Close()
113114
}
114115

@@ -153,7 +154,7 @@ func errorResponse(req *http.Request, code int, msg string) (*http.Response, err
153154
ProtoMinor: 1,
154155

155156
Header: make(http.Header),
156-
Body: ioutil.NopCloser(body),
157+
Body: io.NopCloser(body),
157158
ContentLength: body.Size(),
158159

159160
Request: req,

example/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package main
1616

1717
import (
18-
"io/ioutil"
18+
"os"
1919

2020
"github.com/palantir/go-githubapp/githubapp"
2121
"github.com/pkg/errors"
@@ -41,7 +41,7 @@ type MyApplicationConfig struct {
4141
func ReadConfig(path string) (*Config, error) {
4242
var c Config
4343

44-
bytes, err := ioutil.ReadFile(path)
44+
bytes, err := os.ReadFile(path)
4545
if err != nil {
4646
return nil, errors.Wrapf(err, "failed reading server config file: %s", path)
4747
}

githubapp/context_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ func TestPrepareRepoContext(t *testing.T) {
3131
ctx := logger.WithContext(context.Background())
3232

3333
_, logger = PrepareRepoContext(ctx, 42, &github.Repository{
34-
Name: github.String("test"),
34+
Name: github.Ptr("test"),
3535
Owner: &github.User{
36-
Login: github.String("mhaypenny"),
36+
Login: github.Ptr("mhaypenny"),
3737
},
3838
})
3939

@@ -60,9 +60,9 @@ func TestPreparePRContext(t *testing.T) {
6060
ctx := logger.WithContext(context.Background())
6161

6262
_, logger = PreparePRContext(ctx, 42, &github.Repository{
63-
Name: github.String("test"),
63+
Name: github.Ptr("test"),
6464
Owner: &github.User{
65-
Login: github.String("mhaypenny"),
65+
Login: github.Ptr("mhaypenny"),
6666
},
6767
}, 128)
6868

@@ -84,7 +84,7 @@ func TestPreparePRContext(t *testing.T) {
8484
assertField(t, "pull request number", 128, entry.Number)
8585
}
8686

87-
func assertField(t *testing.T, name string, expected, actual interface{}) {
87+
func assertField(t *testing.T, name string, expected, actual any) {
8888
if expected != actual {
8989
t.Errorf("incorrect %s: expected %#v (%T), but was %#v (%T)", name, expected, expected, actual, actual)
9090
}

githubapp/dispatcher_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func TestSetAndGetResponder(t *testing.T) {
192192
}
193193

194194
func newHookRequest(eventType, id string, signed bool) *http.Request {
195-
body := []byte(fmt.Sprintf(`{"type":"%s"}`, eventType))
195+
body := fmt.Appendf(nil, `{"type":"%s"}`, eventType)
196196

197197
req := httptest.NewRequest(http.MethodPost, "/api/github/hook", bytes.NewReader(body))
198198
req.Header.Set("Content-Type", "application/json")

githubapp/errors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ func errorCounter(r metrics.Registry, event string) metrics.Counter {
4646

4747
// HandlerPanicError is an error created from a recovered handler panic.
4848
type HandlerPanicError struct {
49-
value interface{}
49+
value any
5050
stack []runtime.Frame
5151
}
5252

5353
// Value returns the exact value with which panic() was called.
54-
func (e HandlerPanicError) Value() interface{} {
54+
func (e HandlerPanicError) Value() any {
5555
return e.value
5656
}
5757

githubapp/middleware_logging_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestClientLogging(t *testing.T) {
4141
t.Fatalf("unexpected error making request: %v", err)
4242
}
4343

44-
assertLogFields(t, out.Bytes(), map[string]interface{}{
44+
assertLogFields(t, out.Bytes(), map[string]any{
4545
"method": "GET",
4646
"status": float64(200),
4747
"request_body": "The request",
@@ -60,7 +60,7 @@ func TestClientLogging(t *testing.T) {
6060
t.Fatalf("unexpected error making request: %v", err)
6161
}
6262

63-
assertLogFields(t, out.Bytes(), map[string]interface{}{
63+
assertLogFields(t, out.Bytes(), map[string]any{
6464
"method": "GET",
6565
"status": float64(200),
6666
"request_body": missingField,
@@ -79,7 +79,7 @@ func TestClientLogging(t *testing.T) {
7979
t.Fatalf("unexpected error making request: %v", err)
8080
}
8181

82-
assertLogFields(t, out.Bytes(), map[string]interface{}{
82+
assertLogFields(t, out.Bytes(), map[string]any{
8383
"method": "GET",
8484
"status": float64(200),
8585
"request_body": "",
@@ -98,7 +98,7 @@ func TestClientLogging(t *testing.T) {
9898
t.Fatalf("unexpected error making request: %v", err)
9999
}
100100

101-
assertLogFields(t, out.Bytes(), map[string]interface{}{
101+
assertLogFields(t, out.Bytes(), map[string]any{
102102
"method": "GET",
103103
"status": float64(200),
104104
"response_body": "The response",
@@ -117,7 +117,7 @@ func TestClientLogging(t *testing.T) {
117117
t.Fatalf("unexpected error making request: %v", err)
118118
}
119119

120-
assertLogFields(t, out.Bytes(), map[string]interface{}{
120+
assertLogFields(t, out.Bytes(), map[string]any{
121121
"method": "GET",
122122
"status": float64(200),
123123
"response_body": missingField,
@@ -187,10 +187,10 @@ func newEmptyRoundTripper() http.RoundTripper {
187187

188188
var missingField struct{}
189189

190-
func assertLogFields(t *testing.T, out []byte, expected map[string]interface{}) {
190+
func assertLogFields(t *testing.T, out []byte, expected map[string]any) {
191191
t.Logf("log output: %s", out)
192192

193-
var actual map[string]interface{}
193+
var actual map[string]any
194194
if err := json.Unmarshal(out, &actual); err != nil {
195195
t.Fatalf("unexpected error unmarshalling log fields: %v", err)
196196
}

githubapp/scheduler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func QueueAsyncScheduler(queueSize int, workers int, opts ...SchedulerOption) Sc
212212
opt(&s.scheduler)
213213
}
214214

215-
for i := 0; i < workers; i++ {
215+
for range workers {
216216
go func() {
217217
for d := range s.queue {
218218
if s.eventAge != nil {

0 commit comments

Comments
 (0)