Skip to content

Commit b984460

Browse files
committed
refactor: change interface{} to any
1 parent 8cf43fe commit b984460

File tree

9 files changed

+20
-20
lines changed

9 files changed

+20
-20
lines changed

atreugo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func New(cfg Config) *Atreugo {
6363
}
6464

6565
if cfg.PanicView != nil {
66-
r.router.PanicHandler = func(ctx *fasthttp.RequestCtx, err interface{}) {
66+
r.router.PanicHandler = func(ctx *fasthttp.RequestCtx, err any) {
6767
actx := AcquireRequestCtx(ctx)
6868
cfg.PanicView(actx, err)
6969
ReleaseRequestCtx(actx)

atreugo_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func Test_New(t *testing.T) { //nolint:funlen,gocognit,gocyclo
4848
err bool
4949
}
5050

51-
jsonMarshalFunc := func(_ io.Writer, _ interface{}) error {
51+
jsonMarshalFunc := func(_ io.Writer, _ any) error {
5252
return nil
5353
}
5454
notFoundView := func(_ *RequestCtx) error {
@@ -59,7 +59,7 @@ func Test_New(t *testing.T) { //nolint:funlen,gocognit,gocyclo
5959
}
6060

6161
panicErr := errors.New("error")
62-
panicView := func(ctx *RequestCtx, err interface{}) {
62+
panicView := func(ctx *RequestCtx, err any) {
6363
ctx.Error(fmt.Sprint(err), fasthttp.StatusInternalServerError)
6464
}
6565

context.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var (
1616
attachedCtxKey = fmt.Sprintf("__attachedCtx::%s__", bytes.Rand(make([]byte, 15)))
1717

1818
requestCtxPool = sync.Pool{
19-
New: func() interface{} {
19+
New: func() any {
2020
ctx := new(RequestCtx)
2121
ctx.jsonMarshalFunc = defaultJSONMarshalFunc
2222

@@ -104,7 +104,7 @@ func (ctx *RequestCtx) MatchedRoutePath() []byte {
104104
// the same key returns the same result.
105105
//
106106
// WARNING: The provided key should not be of type string or any other built-in
107-
// to avoid extra allocating when assigning to an interface{}, context keys often
107+
// to avoid extra allocating when assigning to an any, context keys often
108108
// have concrete type struct{}. Alternatively, exported context key variables' static
109109
// type should be a pointer or interface.
110110
//
@@ -119,7 +119,7 @@ func (ctx *RequestCtx) MatchedRoutePath() []byte {
119119
// ctx.Value("myKey")
120120
//
121121
// to avoid extra allocation.
122-
func (ctx *RequestCtx) Value(key interface{}) interface{} {
122+
func (ctx *RequestCtx) Value(key any) any {
123123
if atomic.CompareAndSwapInt32(&ctx.searchingOnAttachedCtx, 0, 1) {
124124
defer atomic.StoreInt32(&ctx.searchingOnAttachedCtx, 0)
125125

errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func wrapError(err error, message string) error {
88
return fmt.Errorf("%s: %w", message, err)
99
}
1010

11-
func wrapErrorf(err error, message string, args ...interface{}) error {
11+
func wrapErrorf(err error, message string, args ...any) error {
1212
message = fmt.Sprintf(message, args...)
1313

1414
return wrapError(err, message)

response.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import (
88
"github.com/valyala/fasthttp"
99
)
1010

11-
func defaultJSONMarshalFunc(w io.Writer, body interface{}) error {
11+
func defaultJSONMarshalFunc(w io.Writer, body any) error {
1212
return json.NewEncoder(w).Encode(body) // nolint:wrapcheck
1313
}
1414

1515
// JSONResponse return response with body in json format.
16-
func (ctx *RequestCtx) JSONResponse(body interface{}, statusCode ...int) error {
16+
func (ctx *RequestCtx) JSONResponse(body any, statusCode ...int) error {
1717
ctx.Response.Header.SetContentType("application/json")
1818

1919
if len(statusCode) > 0 {

response_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (cj customJSON) MarshalJSON() ([]byte, error) {
2424

2525
func TestJSONResponse(t *testing.T) { //nolint:funlen
2626
type args struct {
27-
body interface{}
27+
body any
2828
statusCode int
2929
jsonMarshalFunc JSONMarshalFunc
3030
}
@@ -74,7 +74,7 @@ func TestJSONResponse(t *testing.T) { //nolint:funlen
7474
args: args{
7575
body: "my custom response",
7676
statusCode: 200,
77-
jsonMarshalFunc: func(w io.Writer, value interface{}) error {
77+
jsonMarshalFunc: func(w io.Writer, value any) error {
7878
_, err := w.Write([]byte(fmt.Sprint(value)))
7979

8080
return err // nolint:wrapcheck

router_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func randomHTTPMethod() string {
4747
return httpMethods[n.Int64()]
4848
}
4949

50-
func catchPanic(testFunc func()) (recv interface{}) {
50+
func catchPanic(testFunc func()) (recv any) {
5151
defer func() {
5252
recv = recover()
5353
}()

types.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import (
1515

1616
// Logger is used for logging messages.
1717
type Logger interface {
18-
Print(v ...interface{})
19-
Printf(format string, args ...interface{})
18+
Print(v ...any)
19+
Printf(format string, args ...any)
2020
}
2121

2222
type preforkServer interface {
2323
ListenAndServe(addr string) error
2424
}
2525

26-
type JSONMarshalFunc func(w io.Writer, value interface{}) error
26+
type JSONMarshalFunc func(w io.Writer, value any) error
2727

2828
// Atreugo implements high performance HTTP server
2929
//
@@ -557,7 +557,7 @@ type View func(*RequestCtx) error
557557
type ErrorView func(*RequestCtx, error, int)
558558

559559
// PanicView must process panics recovered from views, if it's defined in configuration.
560-
type PanicView func(*RequestCtx, interface{})
560+
type PanicView func(*RequestCtx, any)
561561

562562
// Middleware must process all incoming requests before/after defined views.
563563
type Middleware View
@@ -586,4 +586,4 @@ type Middlewares struct {
586586
type PathRewriteFunc func(ctx *RequestCtx) []byte
587587

588588
// JSON is a map whose key is a string and whose value an interface.
589-
type JSON map[string]interface{}
589+
type JSON map[string]any

utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/valyala/fasthttp/prefork"
1010
)
1111

12-
func panicf(s string, args ...interface{}) {
12+
func panicf(s string, args ...any) {
1313
panic(fmt.Sprintf(s, args...))
1414
}
1515

@@ -25,11 +25,11 @@ func viewToHandler(view View, errorView ErrorView) fasthttp.RequestHandler {
2525
}
2626
}
2727

28-
func isEqual(v1, v2 interface{}) bool {
28+
func isEqual(v1, v2 any) bool {
2929
return reflect.ValueOf(v1).Pointer() == reflect.ValueOf(v2).Pointer()
3030
}
3131

32-
func isNil(v interface{}) bool {
32+
func isNil(v any) bool {
3333
return reflect.ValueOf(v).IsNil()
3434
}
3535

0 commit comments

Comments
 (0)