Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions appconfig/appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package appconfig
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -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")
}
Expand Down
11 changes: 6 additions & 5 deletions appconfig/responseplayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
"bytes"
"encoding/base64"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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()
}

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions example/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package main

import (
"io/ioutil"
"os"

"github.com/palantir/go-githubapp/githubapp"
"github.com/pkg/errors"
Expand All @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions githubapp/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
})

Expand All @@ -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)

Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion githubapp/dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions githubapp/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
14 changes: 7 additions & 7 deletions githubapp/middleware_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand All @@ -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": "",
Expand All @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion githubapp/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down