Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gofmt -w -r 'interface{} -> any' . #1624

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion args.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func ReleaseArgs(a *Args) {
}

var argsPool = &sync.Pool{
New: func() interface{} {
New: func() any {
return &Args{}
},
}
Expand Down
2 changes: 1 addition & 1 deletion brotli.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func WriteBrotliLevel(w io.Writer, p []byte, level int) (int, error) {

var stacklessWriteBrotli = stackless.NewFunc(nonblockingWriteBrotli)

func nonblockingWriteBrotli(ctxv interface{}) {
func nonblockingWriteBrotli(ctxv any) {
ctx := ctxv.(*compressCtx)
zw := acquireRealBrotliWriter(ctx.w, ctx.level)

Expand Down
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ func (c *HostClient) releaseConn(cc *clientConn) {
}

func (c *HostClient) acquireWriter(conn net.Conn) *bufio.Writer {
var v interface{}
var v any
if c.clientWriterPool != nil {
v = c.clientWriterPool.Get()
if v == nil {
Expand Down Expand Up @@ -1747,7 +1747,7 @@ func (c *HostClient) releaseWriter(bw *bufio.Writer) {
}

func (c *HostClient) acquireReader(conn net.Conn) *bufio.Reader {
var v interface{}
var v any
if c.clientReaderPool != nil {
v = c.clientReaderPool.Get()
if v == nil {
Expand Down
4 changes: 2 additions & 2 deletions compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func WriteGzipLevel(w io.Writer, p []byte, level int) (int, error) {

var stacklessWriteGzip = stackless.NewFunc(nonblockingWriteGzip)

func nonblockingWriteGzip(ctxv interface{}) {
func nonblockingWriteGzip(ctxv any) {
ctx := ctxv.(*compressCtx)
zw := acquireRealGzipWriter(ctx.w, ctx.level)

Expand Down Expand Up @@ -272,7 +272,7 @@ func WriteDeflateLevel(w io.Writer, p []byte, level int) (int, error) {

var stacklessWriteDeflate = stackless.NewFunc(nonblockingWriteDeflate)

func nonblockingWriteDeflate(ctxv interface{}) {
func nonblockingWriteDeflate(ctxv any) {
ctx := ctxv.(*compressCtx)
zw := acquireRealDeflateWriter(ctx.w, ctx.level)

Expand Down
2 changes: 1 addition & 1 deletion cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func ReleaseCookie(c *Cookie) {
}

var cookiePool = &sync.Pool{
New: func() interface{} {
New: func() any {
return &Cookie{}
},
}
Expand Down
4 changes: 2 additions & 2 deletions expvarhandler/expvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestExpvarHandlerBasic(t *testing.T) {
t.Parallel()

expvar.Publish("customVar", expvar.Func(func() interface{} {
expvar.Publish("customVar", expvar.Func(func() any {
return "foobar"
}))

Expand All @@ -24,7 +24,7 @@ func TestExpvarHandlerBasic(t *testing.T) {

body := ctx.Response.Body()

var m map[string]interface{}
var m map[string]any
if err := json.Unmarshal(body, &m); err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion fasthttpadaptor/adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestNewFastHTTPHandler(t *testing.T) {
}
}

func setContextValueMiddleware(next fasthttp.RequestHandler, key string, value interface{}) fasthttp.RequestHandler {
func setContextValueMiddleware(next fasthttp.RequestHandler, key string, value any) fasthttp.RequestHandler {
return func(ctx *fasthttp.RequestCtx) {
ctx.SetUserValue(key, value)
next(ctx)
Expand Down
2 changes: 1 addition & 1 deletion fasthttputil/pipeconns.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
}

var byteBufferPool = &sync.Pool{
New: func() interface{} {
New: func() any {

Check failure on line 338 in fasthttputil/pipeconns.go

View workflow job for this annotation

GitHub Actions / test (1.17.x, ubuntu-latest)

undefined: any

Check failure on line 338 in fasthttputil/pipeconns.go

View workflow job for this annotation

GitHub Actions / test (1.17.x, ubuntu-latest)

undefined: any
return &byteBuffer{
b: make([]byte, 1024),
}
Expand Down
2 changes: 1 addition & 1 deletion fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type TestLogger struct {
t *testing.T
}

func (t TestLogger) Printf(format string, args ...interface{}) {
func (t TestLogger) Printf(format string, args ...any) {
t.t.Logf(format, args...)
}

Expand Down
2 changes: 1 addition & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2121,7 +2121,7 @@ func copyZeroAlloc(w io.Writer, r io.Reader) (int64, error) {
}

var copyBufPool = sync.Pool{
New: func() interface{} {
New: func() any {
return make([]byte, 4096)
},
}
Expand Down
2 changes: 1 addition & 1 deletion prefork/prefork.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
// Logger is used for logging formatted messages.
type Logger interface {
// Printf must have the same semantics as log.Printf.
Printf(format string, args ...interface{})
Printf(format string, args ...any)
}

// Prefork implements fasthttp server prefork
Expand Down
20 changes: 10 additions & 10 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ func (ctx *RequestCtx) Hijacked() bool {
// All the values are removed from ctx after returning from the top
// RequestHandler. Additionally, Close method is called on each value
// implementing io.Closer before removing the value from ctx.
func (ctx *RequestCtx) SetUserValue(key interface{}, value interface{}) {
func (ctx *RequestCtx) SetUserValue(key, value any) {
ctx.userValues.Set(key, value)
}

Expand All @@ -687,26 +687,26 @@ func (ctx *RequestCtx) SetUserValue(key interface{}, value interface{}) {
// functions involved in request processing.
//
// All the values stored in ctx are deleted after returning from RequestHandler.
func (ctx *RequestCtx) SetUserValueBytes(key []byte, value interface{}) {
func (ctx *RequestCtx) SetUserValueBytes(key []byte, value any) {
ctx.userValues.SetBytes(key, value)
}

// UserValue returns the value stored via SetUserValue* under the given key.
func (ctx *RequestCtx) UserValue(key interface{}) interface{} {
func (ctx *RequestCtx) UserValue(key any) any {
return ctx.userValues.Get(key)
}

// UserValueBytes returns the value stored via SetUserValue*
// under the given key.
func (ctx *RequestCtx) UserValueBytes(key []byte) interface{} {
func (ctx *RequestCtx) UserValueBytes(key []byte) any {
return ctx.userValues.GetBytes(key)
}

// VisitUserValues calls visitor for each existing userValue with a key that is a string or []byte.
//
// visitor must not retain references to key and value after returning.
// Make key and/or value copies if you need storing them after returning.
func (ctx *RequestCtx) VisitUserValues(visitor func([]byte, interface{})) {
func (ctx *RequestCtx) VisitUserValues(visitor func([]byte, any)) {
for i, n := 0, len(ctx.userValues); i < n; i++ {
kv := &ctx.userValues[i]
if _, ok := kv.key.(string); ok {
Expand All @@ -719,7 +719,7 @@ func (ctx *RequestCtx) VisitUserValues(visitor func([]byte, interface{})) {
//
// visitor must not retain references to key and value after returning.
// Make key and/or value copies if you need storing them after returning.
func (ctx *RequestCtx) VisitUserValuesAll(visitor func(interface{}, interface{})) {
func (ctx *RequestCtx) VisitUserValuesAll(visitor func(any, any)) {
for i, n := 0, len(ctx.userValues); i < n; i++ {
kv := &ctx.userValues[i]
visitor(kv.key, kv.value)
Expand All @@ -732,7 +732,7 @@ func (ctx *RequestCtx) ResetUserValues() {
}

// RemoveUserValue removes the given key and the value under it in ctx.
func (ctx *RequestCtx) RemoveUserValue(key interface{}) {
func (ctx *RequestCtx) RemoveUserValue(key any) {
ctx.userValues.Remove(key)
}

Expand Down Expand Up @@ -854,7 +854,7 @@ func (r *firstByteReader) Read(b []byte) (int, error) {
// Logger is used for logging formatted messages.
type Logger interface {
// Printf must have the same semantics as log.Printf.
Printf(format string, args ...interface{})
Printf(format string, args ...any)
}

var ctxLoggerLock sync.Mutex
Expand All @@ -864,7 +864,7 @@ type ctxLogger struct {
logger Logger
}

func (cl *ctxLogger) Printf(format string, args ...interface{}) {
func (cl *ctxLogger) Printf(format string, args ...any) {
msg := fmt.Sprintf(format, args...)
ctxLoggerLock.Lock()
cl.logger.Printf("%.3f %s - %s", time.Since(cl.ctx.ConnTime()).Seconds(), cl.ctx.String(), msg)
Expand Down Expand Up @@ -2752,7 +2752,7 @@ func (ctx *RequestCtx) Err() error {
//
// This method is present to make RequestCtx implement the context interface.
// This method is the same as calling ctx.UserValue(key)
func (ctx *RequestCtx) Value(key interface{}) interface{} {
func (ctx *RequestCtx) Value(key any) any {
return ctx.UserValue(key)
}

Expand Down
4 changes: 2 additions & 2 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ func TestRequestCtxUserValue(t *testing.T) {
}
}
vlen := 0
ctx.VisitUserValues(func(key []byte, value interface{}) {
ctx.VisitUserValues(func(key []byte, value any) {
vlen++
v := ctx.UserValue(key)
if v != value {
Expand Down Expand Up @@ -4293,7 +4293,7 @@ type testLogger struct {
out string
}

func (cl *testLogger) Printf(format string, args ...interface{}) {
func (cl *testLogger) Printf(format string, args ...any) {
cl.lock.Lock()
cl.out += fmt.Sprintf(format, args...)[6:] + "\n"
cl.lock.Unlock()
Expand Down
8 changes: 4 additions & 4 deletions stackless/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//
// The stackless wrapper returns false if the call cannot be processed
// at the moment due to high load.
func NewFunc(f func(ctx interface{})) func(ctx interface{}) bool {
func NewFunc(f func(ctx any)) func(ctx any) bool {

Check failure on line 21 in stackless/func.go

View workflow job for this annotation

GitHub Actions / test (1.17.x, ubuntu-latest)

undefined: any

Check failure on line 21 in stackless/func.go

View workflow job for this annotation

GitHub Actions / test (1.17.x, ubuntu-latest)

undefined: any
if f == nil {
// developer sanity-check
panic("BUG: f cannot be nil")
Expand All @@ -33,7 +33,7 @@
}
var once sync.Once

return func(ctx interface{}) bool {
return func(ctx any) bool {

Check failure on line 36 in stackless/func.go

View workflow job for this annotation

GitHub Actions / test (1.17.x, ubuntu-latest)

undefined: any

Check failure on line 36 in stackless/func.go

View workflow job for this annotation

GitHub Actions / test (1.17.x, ubuntu-latest)

undefined: any
once.Do(onceInit)
fw := getFuncWork()
fw.ctx = ctx
Expand All @@ -50,7 +50,7 @@
}
}

func funcWorker(funcWorkCh <-chan *funcWork, f func(ctx interface{})) {
func funcWorker(funcWorkCh <-chan *funcWork, f func(ctx any)) {

Check failure on line 53 in stackless/func.go

View workflow job for this annotation

GitHub Actions / test (1.17.x, ubuntu-latest)

undefined: any

Check failure on line 53 in stackless/func.go

View workflow job for this annotation

GitHub Actions / test (1.17.x, ubuntu-latest)

undefined: any
for fw := range funcWorkCh {
f(fw.ctx)
fw.done <- struct{}{}
Expand All @@ -75,6 +75,6 @@
var funcWorkPool sync.Pool

type funcWork struct {
ctx interface{}
ctx any

Check failure on line 78 in stackless/func.go

View workflow job for this annotation

GitHub Actions / test (1.17.x, ubuntu-latest)

undefined: any
done chan struct{}
}
6 changes: 3 additions & 3 deletions stackless/func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestNewFuncSimple(t *testing.T) {
t.Parallel()

var n uint64
f := NewFunc(func(ctx interface{}) {
f := NewFunc(func(ctx any) {
atomic.AddUint64(&n, uint64(ctx.(int)))
})

Expand All @@ -30,10 +30,10 @@ func TestNewFuncMulti(t *testing.T) {
t.Parallel()

var n1, n2 uint64
f1 := NewFunc(func(ctx interface{}) {
f1 := NewFunc(func(ctx any) {
atomic.AddUint64(&n1, uint64(ctx.(int)))
})
f2 := NewFunc(func(ctx interface{}) {
f2 := NewFunc(func(ctx any) {
atomic.AddUint64(&n2, uint64(ctx.(int)))
})

Expand Down
2 changes: 1 addition & 1 deletion stackless/func_timing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func BenchmarkFuncOverhead(b *testing.B) {
var n uint64
f := NewFunc(func(ctx interface{}) {
f := NewFunc(func(ctx any) {
atomic.AddUint64(&n, *(ctx.(*uint64)))
})
b.RunParallel(func(pb *testing.PB) {
Expand Down
2 changes: 1 addition & 1 deletion stackless/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

var stacklessWriterFunc = NewFunc(writerFunc)

func writerFunc(ctx interface{}) {
func writerFunc(ctx any) {

Check failure on line 103 in stackless/writer.go

View workflow job for this annotation

GitHub Actions / test (1.17.x, ubuntu-latest)

undefined: any
w := ctx.(*writer)
switch w.op {
case opWrite:
Expand Down
2 changes: 1 addition & 1 deletion streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func releaseRequestStream(rs *requestStream) {
}

var requestStreamPool = sync.Pool{
New: func() interface{} {
New: func() any {
return &requestStream{}
},
}
2 changes: 1 addition & 1 deletion tcpdialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func (d *TCPDialer) tcpAddrsClean() {
for {
time.Sleep(time.Second)
t := time.Now()
d.tcpAddrsMap.Range(func(k, v interface{}) bool {
d.tcpAddrsMap.Range(func(k, v any) bool {
if e, ok := v.(*tcpAddrEntry); ok && t.Sub(e.resolveTime) > expireDuration {
d.tcpAddrsMap.Delete(k)
}
Expand Down
2 changes: 1 addition & 1 deletion uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func ReleaseURI(u *URI) {
}

var uriPool = &sync.Pool{
New: func() interface{} {
New: func() any {
return &URI{}
},
}
Expand Down
14 changes: 7 additions & 7 deletions userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
)

type userDataKV struct {
key interface{}
value interface{}
key any
value any
}

type userData []userDataKV

func (d *userData) Set(key interface{}, value interface{}) {
func (d *userData) Set(key, value any) {
if b, ok := key.([]byte); ok {
key = string(b)
}
Expand Down Expand Up @@ -46,11 +46,11 @@ func (d *userData) Set(key interface{}, value interface{}) {
*d = args
}

func (d *userData) SetBytes(key []byte, value interface{}) {
func (d *userData) SetBytes(key []byte, value any) {
d.Set(key, value)
}

func (d *userData) Get(key interface{}) interface{} {
func (d *userData) Get(key any) any {
if b, ok := key.([]byte); ok {
key = b2s(b)
}
Expand All @@ -65,7 +65,7 @@ func (d *userData) Get(key interface{}) interface{} {
return nil
}

func (d *userData) GetBytes(key []byte) interface{} {
func (d *userData) GetBytes(key []byte) any {
return d.Get(key)
}

Expand All @@ -81,7 +81,7 @@ func (d *userData) Reset() {
*d = (*d)[:0]
}

func (d *userData) Remove(key interface{}) {
func (d *userData) Remove(key any) {
if b, ok := key.([]byte); ok {
key = b2s(b)
}
Expand Down
2 changes: 1 addition & 1 deletion userdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestUserData(t *testing.T) {
}
}

func testUserDataGet(t *testing.T, u *userData, key []byte, value interface{}) {
func testUserDataGet(t *testing.T, u *userData, key []byte, value any) {
v := u.GetBytes(key)
if v == nil && value != nil {
t.Fatalf("cannot obtain value for key=%q", key)
Expand Down
Loading
Loading