diff --git a/binary.go b/binary.go index d02d4a1..0b81236 100644 --- a/binary.go +++ b/binary.go @@ -55,7 +55,7 @@ func (w *BitsWriter) SetWriteCallback(cb BitsWriterWriteCallback) { // - []byte: processed as n bytes, n being the length of the input // - bool: processed as one bit // - uint8/uint16/uint32/uint64: processed as n bits, if type is uintn -func (w *BitsWriter) Write(i interface{}) error { +func (w *BitsWriter) Write(i any) error { // Transform input into "10010" format switch a := i.(type) { @@ -244,7 +244,7 @@ func (w *BitsWriter) writeBitsN(toWrite uint64, n int) (err error) { } // WriteN writes the input into n bits -func (w *BitsWriter) WriteN(i interface{}, n int) error { +func (w *BitsWriter) WriteN(i any, n int) error { var toWrite uint64 switch a := i.(type) { case uint8: @@ -276,14 +276,14 @@ func NewBitsWriterBatch(w *BitsWriter) BitsWriterBatch { } // Calls BitsWriter.Write if there was no write error before -func (b *BitsWriterBatch) Write(i interface{}) { +func (b *BitsWriterBatch) Write(i any) { if b.err == nil { b.err = b.w.Write(i) } } // Calls BitsWriter.WriteN if there was no write error before -func (b *BitsWriterBatch) WriteN(i interface{}, n int) { +func (b *BitsWriterBatch) WriteN(i any, n int) { if b.err == nil { b.err = b.w.WriteN(i, n) } diff --git a/binary_test.go b/binary_test.go index 0ac5faf..43e1ab1 100644 --- a/binary_test.go +++ b/binary_test.go @@ -162,7 +162,7 @@ func TestNewBitsWriterBatch(t *testing.T) { func BenchmarkBitsWriter_Write(b *testing.B) { benchmarks := []struct { - input interface{} + input any }{ {"000000"}, {false}, @@ -191,7 +191,7 @@ func BenchmarkBitsWriter_Write(b *testing.B) { func BenchmarkBitsWriter_WriteN(b *testing.B) { type benchData struct { - i interface{} + i any n int } benchmarks := make([]benchData, 0, 128) diff --git a/event.go b/event.go index 66de4d3..039a7a9 100644 --- a/event.go +++ b/event.go @@ -4,7 +4,7 @@ import ( "sync" ) -type EventHandler func(payload interface{}) (delete bool) +type EventHandler func(payload any) (delete bool) type EventName string @@ -59,7 +59,7 @@ func (m *EventManager) Off(id uint64) { } } -func (m *EventManager) Emit(n EventName, payload interface{}) { +func (m *EventManager) Emit(n EventName, payload any) { // Loop through handlers for _, h := range m.handlers(n) { if h.h(payload) { diff --git a/event_test.go b/event_test.go index d15a1e3..ada0078 100644 --- a/event_test.go +++ b/event_test.go @@ -14,12 +14,12 @@ func TestEvent(t *testing.T) { eventName3 astikit.EventName = "event-name-3" ) m := astikit.NewEventManager() - ons := make(map[astikit.EventName][]interface{}) - m.On(eventName1, func(payload interface{}) (delete bool) { + ons := make(map[astikit.EventName][]any) + m.On(eventName1, func(payload any) (delete bool) { ons[eventName1] = append(ons[eventName1], payload) return true }) - id := m.On(eventName3, func(payload interface{}) (delete bool) { + id := m.On(eventName3, func(payload any) (delete bool) { ons[eventName3] = append(ons[eventName3], payload) return false }) @@ -34,7 +34,7 @@ func TestEvent(t *testing.T) { m.Off(id) m.Emit(eventName3, 3) - if e, g := map[astikit.EventName][]interface{}{ + if e, g := map[astikit.EventName][]any{ eventName1: {1}, eventName3: {1, 2}, }, ons; !reflect.DeepEqual(e, g) { diff --git a/go.mod b/go.mod index 8f3c2bc..e8cb881 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/asticode/go-astikit -go 1.13 +go 1.18 diff --git a/http.go b/http.go index 1cded75..348e35a 100644 --- a/http.go +++ b/http.go @@ -197,9 +197,9 @@ type HTTPSenderStatusCodeFunc func(code int) error // HTTPSendJSONOptions represents SendJSON options type HTTPSendJSONOptions struct { - BodyError interface{} - BodyIn interface{} - BodyOut interface{} + BodyError any + BodyIn any + BodyOut any Context context.Context HeadersIn map[string]string HeadersOut HTTPSenderHeaderFunc diff --git a/json.go b/json.go index 39de265..8da0320 100644 --- a/json.go +++ b/json.go @@ -6,7 +6,7 @@ import ( "fmt" ) -func JSONEqual(a, b interface{}) bool { +func JSONEqual(a, b any) bool { ba, err := json.Marshal(a) if err != nil { return false @@ -18,7 +18,7 @@ func JSONEqual(a, b interface{}) bool { return bytes.Equal(ba, bb) } -func JSONClone(src, dst interface{}) (err error) { +func JSONClone(src, dst any) (err error) { // Marshal var b []byte if b, err = json.Marshal(src); err != nil { diff --git a/logger.go b/logger.go index 0780a79..35875ff 100644 --- a/logger.go +++ b/logger.go @@ -68,93 +68,93 @@ type CompleteLogger interface { // StdLogger represents a standard logger type StdLogger interface { - Fatal(v ...interface{}) - Fatalf(format string, v ...interface{}) - Print(v ...interface{}) - Printf(format string, v ...interface{}) + Fatal(v ...any) + Fatalf(format string, v ...any) + Print(v ...any) + Printf(format string, v ...any) } // SeverityLogger represents a severity logger type SeverityLogger interface { - Debug(v ...interface{}) - Debugf(format string, v ...interface{}) - Error(v ...interface{}) - Errorf(format string, v ...interface{}) - Info(v ...interface{}) - Infof(format string, v ...interface{}) - Warn(v ...interface{}) - Warnf(format string, v ...interface{}) + Debug(v ...any) + Debugf(format string, v ...any) + Error(v ...any) + Errorf(format string, v ...any) + Info(v ...any) + Infof(format string, v ...any) + Warn(v ...any) + Warnf(format string, v ...any) } type TestLogger interface { - Error(v ...interface{}) - Errorf(format string, v ...interface{}) - Fatal(v ...interface{}) - Fatalf(format string, v ...interface{}) - Log(v ...interface{}) - Logf(format string, v ...interface{}) + Error(v ...any) + Errorf(format string, v ...any) + Fatal(v ...any) + Fatalf(format string, v ...any) + Log(v ...any) + Logf(format string, v ...any) } // SeverityCtxLogger represents a severity with context logger type SeverityCtxLogger interface { - DebugC(ctx context.Context, v ...interface{}) - DebugCf(ctx context.Context, format string, v ...interface{}) - ErrorC(ctx context.Context, v ...interface{}) - ErrorCf(ctx context.Context, format string, v ...interface{}) - FatalC(ctx context.Context, v ...interface{}) - FatalCf(ctx context.Context, format string, v ...interface{}) - InfoC(ctx context.Context, v ...interface{}) - InfoCf(ctx context.Context, format string, v ...interface{}) - WarnC(ctx context.Context, v ...interface{}) - WarnCf(ctx context.Context, format string, v ...interface{}) + DebugC(ctx context.Context, v ...any) + DebugCf(ctx context.Context, format string, v ...any) + ErrorC(ctx context.Context, v ...any) + ErrorCf(ctx context.Context, format string, v ...any) + FatalC(ctx context.Context, v ...any) + FatalCf(ctx context.Context, format string, v ...any) + InfoC(ctx context.Context, v ...any) + InfoCf(ctx context.Context, format string, v ...any) + WarnC(ctx context.Context, v ...any) + WarnCf(ctx context.Context, format string, v ...any) } type SeverityWriteLogger interface { - Write(l LoggerLevel, v ...interface{}) - Writef(l LoggerLevel, format string, v ...interface{}) + Write(l LoggerLevel, v ...any) + Writef(l LoggerLevel, format string, v ...any) } type SeverityWriteCtxLogger interface { - WriteC(ctx context.Context, l LoggerLevel, v ...interface{}) - WriteCf(ctx context.Context, l LoggerLevel, format string, v ...interface{}) + WriteC(ctx context.Context, l LoggerLevel, v ...any) + WriteCf(ctx context.Context, l LoggerLevel, format string, v ...any) } type completeLogger struct { - print, debug, error, fatal, info, warn func(v ...interface{}) - printf, debugf, errorf, fatalf, infof, warnf func(format string, v ...interface{}) - debugC, errorC, fatalC, infoC, warnC func(ctx context.Context, v ...interface{}) - debugCf, errorCf, fatalCf, infoCf, warnCf func(ctx context.Context, format string, v ...interface{}) - write func(l LoggerLevel, v ...interface{}) - writeC func(ctx context.Context, l LoggerLevel, v ...interface{}) - writeCf func(ctx context.Context, l LoggerLevel, format string, v ...interface{}) - writef func(l LoggerLevel, format string, v ...interface{}) + print, debug, error, fatal, info, warn func(v ...any) + printf, debugf, errorf, fatalf, infof, warnf func(format string, v ...any) + debugC, errorC, fatalC, infoC, warnC func(ctx context.Context, v ...any) + debugCf, errorCf, fatalCf, infoCf, warnCf func(ctx context.Context, format string, v ...any) + write func(l LoggerLevel, v ...any) + writeC func(ctx context.Context, l LoggerLevel, v ...any) + writeCf func(ctx context.Context, l LoggerLevel, format string, v ...any) + writef func(l LoggerLevel, format string, v ...any) } func newCompleteLogger() *completeLogger { l := &completeLogger{} - l.debug = func(v ...interface{}) { l.print(v...) } - l.debugf = func(format string, v ...interface{}) { l.printf(format, v...) } - l.debugC = func(ctx context.Context, v ...interface{}) { l.debug(v...) } - l.debugCf = func(ctx context.Context, format string, v ...interface{}) { l.debugf(format, v...) } - l.error = func(v ...interface{}) { l.print(v...) } - l.errorf = func(format string, v ...interface{}) { l.printf(format, v...) } - l.errorC = func(ctx context.Context, v ...interface{}) { l.error(v...) } - l.errorCf = func(ctx context.Context, format string, v ...interface{}) { l.errorf(format, v...) } - l.fatal = func(v ...interface{}) { l.print(v...) } - l.fatalf = func(format string, v ...interface{}) { l.printf(format, v...) } - l.fatalC = func(ctx context.Context, v ...interface{}) { l.fatal(v...) } - l.fatalCf = func(ctx context.Context, format string, v ...interface{}) { l.fatalf(format, v...) } - l.info = func(v ...interface{}) { l.print(v...) } - l.infof = func(format string, v ...interface{}) { l.printf(format, v...) } - l.infoC = func(ctx context.Context, v ...interface{}) { l.info(v...) } - l.infoCf = func(ctx context.Context, format string, v ...interface{}) { l.infof(format, v...) } - l.print = func(v ...interface{}) {} - l.printf = func(format string, v ...interface{}) {} - l.warn = func(v ...interface{}) { l.print(v...) } - l.warnf = func(format string, v ...interface{}) { l.printf(format, v...) } - l.warnC = func(ctx context.Context, v ...interface{}) { l.warn(v...) } - l.warnCf = func(ctx context.Context, format string, v ...interface{}) { l.warnf(format, v...) } - l.write = func(lv LoggerLevel, v ...interface{}) { + l.debug = func(v ...any) { l.print(v...) } + l.debugf = func(format string, v ...any) { l.printf(format, v...) } + l.debugC = func(ctx context.Context, v ...any) { l.debug(v...) } + l.debugCf = func(ctx context.Context, format string, v ...any) { l.debugf(format, v...) } + l.error = func(v ...any) { l.print(v...) } + l.errorf = func(format string, v ...any) { l.printf(format, v...) } + l.errorC = func(ctx context.Context, v ...any) { l.error(v...) } + l.errorCf = func(ctx context.Context, format string, v ...any) { l.errorf(format, v...) } + l.fatal = func(v ...any) { l.print(v...) } + l.fatalf = func(format string, v ...any) { l.printf(format, v...) } + l.fatalC = func(ctx context.Context, v ...any) { l.fatal(v...) } + l.fatalCf = func(ctx context.Context, format string, v ...any) { l.fatalf(format, v...) } + l.info = func(v ...any) { l.print(v...) } + l.infof = func(format string, v ...any) { l.printf(format, v...) } + l.infoC = func(ctx context.Context, v ...any) { l.info(v...) } + l.infoCf = func(ctx context.Context, format string, v ...any) { l.infof(format, v...) } + l.print = func(v ...any) {} + l.printf = func(format string, v ...any) {} + l.warn = func(v ...any) { l.print(v...) } + l.warnf = func(format string, v ...any) { l.printf(format, v...) } + l.warnC = func(ctx context.Context, v ...any) { l.warn(v...) } + l.warnCf = func(ctx context.Context, format string, v ...any) { l.warnf(format, v...) } + l.write = func(lv LoggerLevel, v ...any) { switch lv { case LoggerLevelDebug: l.debug(v...) @@ -168,7 +168,7 @@ func newCompleteLogger() *completeLogger { l.info(v...) } } - l.writeC = func(ctx context.Context, lv LoggerLevel, v ...interface{}) { + l.writeC = func(ctx context.Context, lv LoggerLevel, v ...any) { switch lv { case LoggerLevelDebug: l.debugC(ctx, v...) @@ -182,7 +182,7 @@ func newCompleteLogger() *completeLogger { l.infoC(ctx, v...) } } - l.writeCf = func(ctx context.Context, lv LoggerLevel, format string, v ...interface{}) { + l.writeCf = func(ctx context.Context, lv LoggerLevel, format string, v ...any) { switch lv { case LoggerLevelDebug: l.debugCf(ctx, format, v...) @@ -196,7 +196,7 @@ func newCompleteLogger() *completeLogger { l.infoCf(ctx, format, v...) } } - l.writef = func(lv LoggerLevel, format string, v ...interface{}) { + l.writef = func(lv LoggerLevel, format string, v ...any) { switch lv { case LoggerLevelDebug: l.debugf(format, v...) @@ -213,46 +213,46 @@ func newCompleteLogger() *completeLogger { return l } -func (l *completeLogger) Debug(v ...interface{}) { l.debug(v...) } -func (l *completeLogger) Debugf(format string, v ...interface{}) { l.debugf(format, v...) } -func (l *completeLogger) DebugC(ctx context.Context, v ...interface{}) { l.debugC(ctx, v...) } -func (l *completeLogger) DebugCf(ctx context.Context, format string, v ...interface{}) { +func (l *completeLogger) Debug(v ...any) { l.debug(v...) } +func (l *completeLogger) Debugf(format string, v ...any) { l.debugf(format, v...) } +func (l *completeLogger) DebugC(ctx context.Context, v ...any) { l.debugC(ctx, v...) } +func (l *completeLogger) DebugCf(ctx context.Context, format string, v ...any) { l.debugCf(ctx, format, v...) } -func (l *completeLogger) Error(v ...interface{}) { l.error(v...) } -func (l *completeLogger) Errorf(format string, v ...interface{}) { l.errorf(format, v...) } -func (l *completeLogger) ErrorC(ctx context.Context, v ...interface{}) { l.errorC(ctx, v...) } -func (l *completeLogger) ErrorCf(ctx context.Context, format string, v ...interface{}) { +func (l *completeLogger) Error(v ...any) { l.error(v...) } +func (l *completeLogger) Errorf(format string, v ...any) { l.errorf(format, v...) } +func (l *completeLogger) ErrorC(ctx context.Context, v ...any) { l.errorC(ctx, v...) } +func (l *completeLogger) ErrorCf(ctx context.Context, format string, v ...any) { l.errorCf(ctx, format, v...) } -func (l *completeLogger) Fatal(v ...interface{}) { l.fatal(v...) } -func (l *completeLogger) Fatalf(format string, v ...interface{}) { l.fatalf(format, v...) } -func (l *completeLogger) FatalC(ctx context.Context, v ...interface{}) { l.fatalC(ctx, v...) } -func (l *completeLogger) FatalCf(ctx context.Context, format string, v ...interface{}) { +func (l *completeLogger) Fatal(v ...any) { l.fatal(v...) } +func (l *completeLogger) Fatalf(format string, v ...any) { l.fatalf(format, v...) } +func (l *completeLogger) FatalC(ctx context.Context, v ...any) { l.fatalC(ctx, v...) } +func (l *completeLogger) FatalCf(ctx context.Context, format string, v ...any) { l.fatalCf(ctx, format, v...) } -func (l *completeLogger) Info(v ...interface{}) { l.info(v...) } -func (l *completeLogger) Infof(format string, v ...interface{}) { l.infof(format, v...) } -func (l *completeLogger) InfoC(ctx context.Context, v ...interface{}) { l.infoC(ctx, v...) } -func (l *completeLogger) InfoCf(ctx context.Context, format string, v ...interface{}) { +func (l *completeLogger) Info(v ...any) { l.info(v...) } +func (l *completeLogger) Infof(format string, v ...any) { l.infof(format, v...) } +func (l *completeLogger) InfoC(ctx context.Context, v ...any) { l.infoC(ctx, v...) } +func (l *completeLogger) InfoCf(ctx context.Context, format string, v ...any) { l.infoCf(ctx, format, v...) } -func (l *completeLogger) Print(v ...interface{}) { l.print(v...) } -func (l *completeLogger) Printf(format string, v ...interface{}) { l.printf(format, v...) } -func (l *completeLogger) Warn(v ...interface{}) { l.warn(v...) } -func (l *completeLogger) Warnf(format string, v ...interface{}) { l.warnf(format, v...) } -func (l *completeLogger) WarnC(ctx context.Context, v ...interface{}) { l.warnC(ctx, v...) } -func (l *completeLogger) WarnCf(ctx context.Context, format string, v ...interface{}) { +func (l *completeLogger) Print(v ...any) { l.print(v...) } +func (l *completeLogger) Printf(format string, v ...any) { l.printf(format, v...) } +func (l *completeLogger) Warn(v ...any) { l.warn(v...) } +func (l *completeLogger) Warnf(format string, v ...any) { l.warnf(format, v...) } +func (l *completeLogger) WarnC(ctx context.Context, v ...any) { l.warnC(ctx, v...) } +func (l *completeLogger) WarnCf(ctx context.Context, format string, v ...any) { l.warnCf(ctx, format, v...) } -func (l *completeLogger) Write(lv LoggerLevel, v ...interface{}) { l.write(lv, v...) } -func (l *completeLogger) Writef(lv LoggerLevel, format string, v ...interface{}) { +func (l *completeLogger) Write(lv LoggerLevel, v ...any) { l.write(lv, v...) } +func (l *completeLogger) Writef(lv LoggerLevel, format string, v ...any) { l.writef(lv, format, v...) } -func (l *completeLogger) WriteC(ctx context.Context, lv LoggerLevel, v ...interface{}) { +func (l *completeLogger) WriteC(ctx context.Context, lv LoggerLevel, v ...any) { l.writeC(ctx, lv, v...) } -func (l *completeLogger) WriteCf(ctx context.Context, lv LoggerLevel, format string, v ...interface{}) { +func (l *completeLogger) WriteCf(ctx context.Context, lv LoggerLevel, format string, v ...any) { l.writeCf(ctx, lv, format, v...) } diff --git a/map.go b/map.go index 8ec17b2..b68a544 100644 --- a/map.go +++ b/map.go @@ -7,21 +7,21 @@ import ( // BiMap represents a bidirectional map type BiMap struct { - forward map[interface{}]interface{} - inverse map[interface{}]interface{} + forward map[any]any + inverse map[any]any m *sync.Mutex } // NewBiMap creates a new BiMap func NewBiMap() *BiMap { return &BiMap{ - forward: make(map[interface{}]interface{}), - inverse: make(map[interface{}]interface{}), + forward: make(map[any]any), + inverse: make(map[any]any), m: &sync.Mutex{}, } } -func (m *BiMap) get(k interface{}, i map[interface{}]interface{}) (v interface{}, ok bool) { +func (m *BiMap) get(k any, i map[any]any) (v any, ok bool) { m.m.Lock() defer m.m.Unlock() v, ok = i[k] @@ -29,13 +29,13 @@ func (m *BiMap) get(k interface{}, i map[interface{}]interface{}) (v interface{} } // Get gets the value in the forward map based on the provided key -func (m *BiMap) Get(k interface{}) (interface{}, bool) { return m.get(k, m.forward) } +func (m *BiMap) Get(k any) (any, bool) { return m.get(k, m.forward) } // GetInverse gets the value in the inverse map based on the provided key -func (m *BiMap) GetInverse(k interface{}) (interface{}, bool) { return m.get(k, m.inverse) } +func (m *BiMap) GetInverse(k any) (any, bool) { return m.get(k, m.inverse) } // MustGet gets the value in the forward map based on the provided key and panics if key is not found -func (m *BiMap) MustGet(k interface{}) interface{} { +func (m *BiMap) MustGet(k any) any { v, ok := m.get(k, m.forward) if !ok { panic(fmt.Sprintf("astikit: key %+v not found in foward map", k)) @@ -44,7 +44,7 @@ func (m *BiMap) MustGet(k interface{}) interface{} { } // MustGetInverse gets the value in the inverse map based on the provided key and panics if key is not found -func (m *BiMap) MustGetInverse(k interface{}) interface{} { +func (m *BiMap) MustGetInverse(k any) any { v, ok := m.get(k, m.inverse) if !ok { panic(fmt.Sprintf("astikit: key %+v not found in inverse map", k)) @@ -52,7 +52,7 @@ func (m *BiMap) MustGetInverse(k interface{}) interface{} { return v } -func (m *BiMap) set(k, v interface{}, f, i map[interface{}]interface{}) *BiMap { +func (m *BiMap) set(k, v any, f, i map[any]any) *BiMap { m.m.Lock() defer m.m.Unlock() f[k] = v @@ -61,7 +61,7 @@ func (m *BiMap) set(k, v interface{}, f, i map[interface{}]interface{}) *BiMap { } // Set sets the value in the forward and inverse map for the provided forward key -func (m *BiMap) Set(k, v interface{}) *BiMap { return m.set(k, v, m.forward, m.inverse) } +func (m *BiMap) Set(k, v any) *BiMap { return m.set(k, v, m.forward, m.inverse) } // SetInverse sets the value in the forward and inverse map for the provided inverse key -func (m *BiMap) SetInverse(k, v interface{}) *BiMap { return m.set(k, v, m.inverse, m.forward) } +func (m *BiMap) SetInverse(k, v any) *BiMap { return m.set(k, v, m.inverse, m.forward) } diff --git a/stat.go b/stat.go index 48c7e5a..17da4bc 100644 --- a/stat.go +++ b/stat.go @@ -22,7 +22,7 @@ type Stater struct { type StatOptions struct { Metadata *StatMetadata // Either a StatValuer or StatValuerOverTime - Valuer interface{} + Valuer any } // StatsHandleFunc is a method that can handle stat values @@ -38,19 +38,19 @@ type StatMetadata struct { // StatValuer represents a stat valuer type StatValuer interface { - Value(delta time.Duration) interface{} + Value(delta time.Duration) any } -type StatValuerFunc func(d time.Duration) interface{} +type StatValuerFunc func(d time.Duration) any -func (f StatValuerFunc) Value(d time.Duration) interface{} { +func (f StatValuerFunc) Value(d time.Duration) any { return f(d) } // StatValue represents a stat value type StatValue struct { *StatMetadata - Value interface{} + Value any } // StaterOptions represents stater options @@ -103,7 +103,7 @@ func (s *Stater) Start(ctx context.Context) { s.m.Lock() for _, o := range s.ss { // Get value - var v interface{} + var v any if h, ok := o.Valuer.(StatValuer); ok { v = h.Value(delta) } else { @@ -161,7 +161,7 @@ func NewAtomicUint64RateStat(v *uint64) *AtomicUint64RateStat { return &AtomicUint64RateStat{v: v} } -func (s *AtomicUint64RateStat) Value(d time.Duration) interface{} { +func (s *AtomicUint64RateStat) Value(d time.Duration) any { current := atomic.LoadUint64(s.v) defer func() { s.last = ¤t }() if d <= 0 { @@ -183,7 +183,7 @@ func NewAtomicDurationPercentageStat(d *AtomicDuration) *AtomicDurationPercentag return &AtomicDurationPercentageStat{d: d} } -func (s *AtomicDurationPercentageStat) Value(d time.Duration) interface{} { +func (s *AtomicDurationPercentageStat) Value(d time.Duration) any { current := s.d.Duration() defer func() { s.last = ¤t }() if d <= 0 { @@ -210,7 +210,7 @@ func NewAtomicDurationAvgStat(d *AtomicDuration, count *uint64) *AtomicDurationA } } -func (s *AtomicDurationAvgStat) Value(_ time.Duration) interface{} { +func (s *AtomicDurationAvgStat) Value(_ time.Duration) any { current := s.d.Duration() currentCount := atomic.LoadUint64(s.count) defer func() { diff --git a/stat_test.go b/stat_test.go index 3491716..1407ae1 100644 --- a/stat_test.go +++ b/stat_test.go @@ -36,7 +36,7 @@ func TestStater(t *testing.T) { v3 := NewAtomicDurationAvgStat(d3, &u1) m3 := &StatMetadata{Description: "3"} o3 := StatOptions{Metadata: m3, Valuer: v3} - v4 := StatValuerFunc(func(d time.Duration) interface{} { return 42 }) + v4 := StatValuerFunc(func(d time.Duration) any { return 42 }) m4 := &StatMetadata{Description: "4"} o4 := StatOptions{Metadata: m4, Valuer: v4} diff --git a/sync.go b/sync.go index 4c0bbdc..9ed630a 100644 --- a/sync.go +++ b/sync.go @@ -231,7 +231,7 @@ type BufferPool struct { // NewBufferPool creates a new BufferPool func NewBufferPool() *BufferPool { - return &BufferPool{bp: &sync.Pool{New: func() interface{} { return &bytes.Buffer{} }}} + return &BufferPool{bp: &sync.Pool{New: func() any { return &bytes.Buffer{} }}} } // New creates a new BufferPoolItem @@ -359,7 +359,7 @@ type EventerOptions struct { } // EventerHandler represents a function that can handle the payload of an event -type EventerHandler func(payload interface{}) +type EventerHandler func(payload any) // NewEventer creates a new eventer func NewEventer(o EventerOptions) *Eventer { @@ -381,7 +381,7 @@ func (e *Eventer) On(name string, h EventerHandler) { } // Dispatch dispatches a payload for a specific name -func (e *Eventer) Dispatch(name string, payload interface{}) { +func (e *Eventer) Dispatch(name string, payload any) { // Lock e.mh.Lock() defer e.mh.Unlock() @@ -468,7 +468,7 @@ func (m *DebugMutex) caller() (o string) { return } -func (m *DebugMutex) log(fmt string, args ...interface{}) { +func (m *DebugMutex) log(fmt string, args ...any) { if m.ll < LoggerLevelDebug { return } diff --git a/sync_test.go b/sync_test.go index ed6e76b..fa7ebb3 100644 --- a/sync_test.go +++ b/sync_test.go @@ -129,8 +129,8 @@ func TestGoroutineLimiter(t *testing.T) { func TestEventer(t *testing.T) { e := NewEventer(EventerOptions{Chan: ChanOptions{ProcessAll: true}}) var o []string - e.On("1", func(payload interface{}) { o = append(o, payload.(string)) }) - e.On("2", func(payload interface{}) { o = append(o, payload.(string)) }) + e.On("1", func(payload any) { o = append(o, payload.(string)) }) + e.On("2", func(payload any) { o = append(o, payload.(string)) }) go func() { time.Sleep(10 * time.Millisecond) e.Dispatch("1", "1.1") @@ -149,22 +149,22 @@ type mockedStdLogger struct { ss []string } -func (l *mockedStdLogger) Fatal(v ...interface{}) { +func (l *mockedStdLogger) Fatal(v ...any) { l.m.Lock() defer l.m.Unlock() l.ss = append(l.ss, "fatal: "+fmt.Sprint(v...)) } -func (l *mockedStdLogger) Fatalf(format string, v ...interface{}) { +func (l *mockedStdLogger) Fatalf(format string, v ...any) { l.m.Lock() defer l.m.Unlock() l.ss = append(l.ss, "fatal: "+fmt.Sprintf(format, v...)) } -func (l *mockedStdLogger) Print(v ...interface{}) { +func (l *mockedStdLogger) Print(v ...any) { l.m.Lock() defer l.m.Unlock() l.ss = append(l.ss, "print: "+fmt.Sprint(v...)) } -func (l *mockedStdLogger) Printf(format string, v ...interface{}) { +func (l *mockedStdLogger) Printf(format string, v ...any) { l.m.Lock() defer l.m.Unlock() l.ss = append(l.ss, "print: "+fmt.Sprintf(format, v...)) diff --git a/translator.go b/translator.go index 6cfe966..e5e535f 100644 --- a/translator.go +++ b/translator.go @@ -101,7 +101,7 @@ func (t *Translator) ParseFile(dirPath, path string) (err error) { defer f.Close() // Unmarshal - var p map[string]interface{} + var p map[string]any if err = json.NewDecoder(f).Decode(&p); err != nil { err = fmt.Errorf("astikit: unmarshaling %s failed: %w", path, err) return @@ -134,13 +134,13 @@ func (t *Translator) key(prefix, key string) string { return prefix + "." + key } -func (t *Translator) parse(i map[string]interface{}, prefix string) { +func (t *Translator) parse(i map[string]any, prefix string) { for k, v := range i { p := t.key(prefix, k) switch a := v.(type) { case string: t.p[p] = a - case map[string]interface{}: + case map[string]any: t.parse(a, p) } } @@ -256,7 +256,7 @@ func (t *Translator) Translate(language, key string) string { } // Translatef translates a key into a specific language with optional formatting args -func (t *Translator) Translatef(language, key string, args ...interface{}) string { +func (t *Translator) Translatef(language, key string, args ...any) string { return fmt.Sprintf(t.Translate(language, key), args...) } @@ -270,6 +270,6 @@ func (t *Translator) TranslateC(ctx context.Context, key string) string { return t.Translate(translatorLanguageFromContext(ctx), key) } -func (t *Translator) TranslateCf(ctx context.Context, key string, args ...interface{}) string { +func (t *Translator) TranslateCf(ctx context.Context, key string, args ...any) string { return t.Translatef(translatorLanguageFromContext(ctx), key, args...) } diff --git a/translator_test.go b/translator_test.go index ac983c8..e79b82f 100644 --- a/translator_test.go +++ b/translator_test.go @@ -31,7 +31,7 @@ func TestTranslator(t *testing.T) { // Middleware var o string s := httptest.NewServer(ChainHTTPMiddlewares(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { - var args []interface{} + var args []any if v := r.Header.Get("args"); v != "" { for _, s := range strings.Split(v, ",") { args = append(args, s)