Enabled by using Go 1.18. A bit less verbose.
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
// 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.
)
// 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 {
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 {
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
}
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)
})
}
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() {
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++ {
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.
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')
}