all: use any in place of interface{}
Enabled by using Go 1.18. A bit less verbose. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
parent
42c9af45e1
commit
46826fc4e5
@ -16,8 +16,8 @@ import (
|
||||
// They do not require a trailing newline in the format.
|
||||
// If nil, that level of logging will be silent.
|
||||
type Logger struct {
|
||||
Verbosef func(format string, args ...interface{})
|
||||
Errorf func(format string, args ...interface{})
|
||||
Verbosef func(format string, args ...any)
|
||||
Errorf func(format string, args ...any)
|
||||
}
|
||||
|
||||
// Log levels for use with NewLogger.
|
||||
@ -28,14 +28,14 @@ const (
|
||||
)
|
||||
|
||||
// Function for use in Logger for discarding logged lines.
|
||||
func DiscardLogf(format string, args ...interface{}) {}
|
||||
func DiscardLogf(format string, args ...any) {}
|
||||
|
||||
// NewLogger constructs a Logger that writes to stdout.
|
||||
// It logs at the specified log level and above.
|
||||
// It decorates log lines with the log level, date, time, and prepend.
|
||||
func NewLogger(level int, prepend string) *Logger {
|
||||
logger := &Logger{DiscardLogf, DiscardLogf}
|
||||
logf := func(prefix string) func(string, ...interface{}) {
|
||||
logf := func(prefix string) func(string, ...any) {
|
||||
return log.New(os.Stdout, prefix+": "+prepend, log.Ldate|log.Ltime).Printf
|
||||
}
|
||||
if level >= LogLevelVerbose {
|
||||
|
@ -18,13 +18,13 @@ type WaitPool struct {
|
||||
max uint32
|
||||
}
|
||||
|
||||
func NewWaitPool(max uint32, new func() interface{}) *WaitPool {
|
||||
func NewWaitPool(max uint32, new func() any) *WaitPool {
|
||||
p := &WaitPool{pool: sync.Pool{New: new}, max: max}
|
||||
p.cond = sync.Cond{L: &p.lock}
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *WaitPool) Get() interface{} {
|
||||
func (p *WaitPool) Get() any {
|
||||
if p.max != 0 {
|
||||
p.lock.Lock()
|
||||
for atomic.LoadUint32(&p.count) >= p.max {
|
||||
@ -36,7 +36,7 @@ func (p *WaitPool) Get() interface{} {
|
||||
return p.pool.Get()
|
||||
}
|
||||
|
||||
func (p *WaitPool) Put(x interface{}) {
|
||||
func (p *WaitPool) Put(x any) {
|
||||
p.pool.Put(x)
|
||||
if p.max == 0 {
|
||||
return
|
||||
@ -46,13 +46,13 @@ func (p *WaitPool) Put(x interface{}) {
|
||||
}
|
||||
|
||||
func (device *Device) PopulatePools() {
|
||||
device.pool.messageBuffers = NewWaitPool(PreallocatedBuffersPerPool, func() interface{} {
|
||||
device.pool.messageBuffers = NewWaitPool(PreallocatedBuffersPerPool, func() any {
|
||||
return new([MaxMessageSize]byte)
|
||||
})
|
||||
device.pool.inboundElements = NewWaitPool(PreallocatedBuffersPerPool, func() interface{} {
|
||||
device.pool.inboundElements = NewWaitPool(PreallocatedBuffersPerPool, func() any {
|
||||
return new(QueueInboundElement)
|
||||
})
|
||||
device.pool.outboundElements = NewWaitPool(PreallocatedBuffersPerPool, func() interface{} {
|
||||
device.pool.outboundElements = NewWaitPool(PreallocatedBuffersPerPool, func() any {
|
||||
return new(QueueOutboundElement)
|
||||
})
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ func TestWaitPool(t *testing.T) {
|
||||
if workers-4 <= 0 {
|
||||
t.Skip("Not enough cores")
|
||||
}
|
||||
p := NewWaitPool(uint32(workers-4), func() interface{} { return make([]byte, 16) })
|
||||
p := NewWaitPool(uint32(workers-4), func() any { return make([]byte, 16) })
|
||||
wg.Add(workers)
|
||||
max := uint32(0)
|
||||
updateMax := func() {
|
||||
@ -71,7 +71,7 @@ func BenchmarkWaitPool(b *testing.B) {
|
||||
if workers-4 <= 0 {
|
||||
b.Skip("Not enough cores")
|
||||
}
|
||||
p := NewWaitPool(uint32(workers-4), func() interface{} { return make([]byte, 16) })
|
||||
p := NewWaitPool(uint32(workers-4), func() any { return make([]byte, 16) })
|
||||
wg.Add(workers)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < workers; i++ {
|
||||
|
@ -39,12 +39,12 @@ func (s IPCError) ErrorCode() int64 {
|
||||
return s.code
|
||||
}
|
||||
|
||||
func ipcErrorf(code int64, msg string, args ...interface{}) *IPCError {
|
||||
func ipcErrorf(code int64, msg string, args ...any) *IPCError {
|
||||
return &IPCError{code: code, err: fmt.Errorf(msg, args...)}
|
||||
}
|
||||
|
||||
var byteBufferPool = &sync.Pool{
|
||||
New: func() interface{} { return new(bytes.Buffer) },
|
||||
New: func() any { return new(bytes.Buffer) },
|
||||
}
|
||||
|
||||
// IpcGetOperation implements the WireGuard configuration protocol "get" operation.
|
||||
@ -56,7 +56,7 @@ func (device *Device) IpcGetOperation(w io.Writer) error {
|
||||
buf := byteBufferPool.Get().(*bytes.Buffer)
|
||||
buf.Reset()
|
||||
defer byteBufferPool.Put(buf)
|
||||
sendf := func(format string, args ...interface{}) {
|
||||
sendf := func(format string, args ...any) {
|
||||
fmt.Fprintf(buf, format, args...)
|
||||
buf.WriteByte('\n')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user