Moved to go 1.18 to use any instead of interface{}

This commit is contained in:
Quentin Renard
2025-02-13 11:37:23 +01:00
parent 7c3a7f9e4c
commit 48d50c2eb9
15 changed files with 148 additions and 148 deletions
+4 -4
View File
@@ -55,7 +55,7 @@ func (w *BitsWriter) SetWriteCallback(cb BitsWriterWriteCallback) {
// - []byte: processed as n bytes, n being the length of the input // - []byte: processed as n bytes, n being the length of the input
// - bool: processed as one bit // - bool: processed as one bit
// - uint8/uint16/uint32/uint64: processed as n bits, if type is uintn // - 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 // Transform input into "10010" format
switch a := i.(type) { 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 // 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 var toWrite uint64
switch a := i.(type) { switch a := i.(type) {
case uint8: case uint8:
@@ -276,14 +276,14 @@ func NewBitsWriterBatch(w *BitsWriter) BitsWriterBatch {
} }
// Calls BitsWriter.Write if there was no write error before // 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 { if b.err == nil {
b.err = b.w.Write(i) b.err = b.w.Write(i)
} }
} }
// Calls BitsWriter.WriteN if there was no write error before // 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 { if b.err == nil {
b.err = b.w.WriteN(i, n) b.err = b.w.WriteN(i, n)
} }
+2 -2
View File
@@ -162,7 +162,7 @@ func TestNewBitsWriterBatch(t *testing.T) {
func BenchmarkBitsWriter_Write(b *testing.B) { func BenchmarkBitsWriter_Write(b *testing.B) {
benchmarks := []struct { benchmarks := []struct {
input interface{} input any
}{ }{
{"000000"}, {"000000"},
{false}, {false},
@@ -191,7 +191,7 @@ func BenchmarkBitsWriter_Write(b *testing.B) {
func BenchmarkBitsWriter_WriteN(b *testing.B) { func BenchmarkBitsWriter_WriteN(b *testing.B) {
type benchData struct { type benchData struct {
i interface{} i any
n int n int
} }
benchmarks := make([]benchData, 0, 128) benchmarks := make([]benchData, 0, 128)
+2 -2
View File
@@ -4,7 +4,7 @@ import (
"sync" "sync"
) )
type EventHandler func(payload interface{}) (delete bool) type EventHandler func(payload any) (delete bool)
type EventName string 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 // Loop through handlers
for _, h := range m.handlers(n) { for _, h := range m.handlers(n) {
if h.h(payload) { if h.h(payload) {
+4 -4
View File
@@ -14,12 +14,12 @@ func TestEvent(t *testing.T) {
eventName3 astikit.EventName = "event-name-3" eventName3 astikit.EventName = "event-name-3"
) )
m := astikit.NewEventManager() m := astikit.NewEventManager()
ons := make(map[astikit.EventName][]interface{}) ons := make(map[astikit.EventName][]any)
m.On(eventName1, func(payload interface{}) (delete bool) { m.On(eventName1, func(payload any) (delete bool) {
ons[eventName1] = append(ons[eventName1], payload) ons[eventName1] = append(ons[eventName1], payload)
return true 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) ons[eventName3] = append(ons[eventName3], payload)
return false return false
}) })
@@ -34,7 +34,7 @@ func TestEvent(t *testing.T) {
m.Off(id) m.Off(id)
m.Emit(eventName3, 3) m.Emit(eventName3, 3)
if e, g := map[astikit.EventName][]interface{}{ if e, g := map[astikit.EventName][]any{
eventName1: {1}, eventName1: {1},
eventName3: {1, 2}, eventName3: {1, 2},
}, ons; !reflect.DeepEqual(e, g) { }, ons; !reflect.DeepEqual(e, g) {
+1 -1
View File
@@ -1,3 +1,3 @@
module github.com/asticode/go-astikit module github.com/asticode/go-astikit
go 1.13 go 1.18
+3 -3
View File
@@ -197,9 +197,9 @@ type HTTPSenderStatusCodeFunc func(code int) error
// HTTPSendJSONOptions represents SendJSON options // HTTPSendJSONOptions represents SendJSON options
type HTTPSendJSONOptions struct { type HTTPSendJSONOptions struct {
BodyError interface{} BodyError any
BodyIn interface{} BodyIn any
BodyOut interface{} BodyOut any
Context context.Context Context context.Context
HeadersIn map[string]string HeadersIn map[string]string
HeadersOut HTTPSenderHeaderFunc HeadersOut HTTPSenderHeaderFunc
+2 -2
View File
@@ -6,7 +6,7 @@ import (
"fmt" "fmt"
) )
func JSONEqual(a, b interface{}) bool { func JSONEqual(a, b any) bool {
ba, err := json.Marshal(a) ba, err := json.Marshal(a)
if err != nil { if err != nil {
return false return false
@@ -18,7 +18,7 @@ func JSONEqual(a, b interface{}) bool {
return bytes.Equal(ba, bb) return bytes.Equal(ba, bb)
} }
func JSONClone(src, dst interface{}) (err error) { func JSONClone(src, dst any) (err error) {
// Marshal // Marshal
var b []byte var b []byte
if b, err = json.Marshal(src); err != nil { if b, err = json.Marshal(src); err != nil {
+92 -92
View File
@@ -68,93 +68,93 @@ type CompleteLogger interface {
// StdLogger represents a standard logger // StdLogger represents a standard logger
type StdLogger interface { type StdLogger interface {
Fatal(v ...interface{}) Fatal(v ...any)
Fatalf(format string, v ...interface{}) Fatalf(format string, v ...any)
Print(v ...interface{}) Print(v ...any)
Printf(format string, v ...interface{}) Printf(format string, v ...any)
} }
// SeverityLogger represents a severity logger // SeverityLogger represents a severity logger
type SeverityLogger interface { type SeverityLogger interface {
Debug(v ...interface{}) Debug(v ...any)
Debugf(format string, v ...interface{}) Debugf(format string, v ...any)
Error(v ...interface{}) Error(v ...any)
Errorf(format string, v ...interface{}) Errorf(format string, v ...any)
Info(v ...interface{}) Info(v ...any)
Infof(format string, v ...interface{}) Infof(format string, v ...any)
Warn(v ...interface{}) Warn(v ...any)
Warnf(format string, v ...interface{}) Warnf(format string, v ...any)
} }
type TestLogger interface { type TestLogger interface {
Error(v ...interface{}) Error(v ...any)
Errorf(format string, v ...interface{}) Errorf(format string, v ...any)
Fatal(v ...interface{}) Fatal(v ...any)
Fatalf(format string, v ...interface{}) Fatalf(format string, v ...any)
Log(v ...interface{}) Log(v ...any)
Logf(format string, v ...interface{}) Logf(format string, v ...any)
} }
// SeverityCtxLogger represents a severity with context logger // SeverityCtxLogger represents a severity with context logger
type SeverityCtxLogger interface { type SeverityCtxLogger interface {
DebugC(ctx context.Context, v ...interface{}) DebugC(ctx context.Context, v ...any)
DebugCf(ctx context.Context, format string, v ...interface{}) DebugCf(ctx context.Context, format string, v ...any)
ErrorC(ctx context.Context, v ...interface{}) ErrorC(ctx context.Context, v ...any)
ErrorCf(ctx context.Context, format string, v ...interface{}) ErrorCf(ctx context.Context, format string, v ...any)
FatalC(ctx context.Context, v ...interface{}) FatalC(ctx context.Context, v ...any)
FatalCf(ctx context.Context, format string, v ...interface{}) FatalCf(ctx context.Context, format string, v ...any)
InfoC(ctx context.Context, v ...interface{}) InfoC(ctx context.Context, v ...any)
InfoCf(ctx context.Context, format string, v ...interface{}) InfoCf(ctx context.Context, format string, v ...any)
WarnC(ctx context.Context, v ...interface{}) WarnC(ctx context.Context, v ...any)
WarnCf(ctx context.Context, format string, v ...interface{}) WarnCf(ctx context.Context, format string, v ...any)
} }
type SeverityWriteLogger interface { type SeverityWriteLogger interface {
Write(l LoggerLevel, v ...interface{}) Write(l LoggerLevel, v ...any)
Writef(l LoggerLevel, format string, v ...interface{}) Writef(l LoggerLevel, format string, v ...any)
} }
type SeverityWriteCtxLogger interface { type SeverityWriteCtxLogger interface {
WriteC(ctx context.Context, l LoggerLevel, v ...interface{}) WriteC(ctx context.Context, l LoggerLevel, v ...any)
WriteCf(ctx context.Context, l LoggerLevel, format string, v ...interface{}) WriteCf(ctx context.Context, l LoggerLevel, format string, v ...any)
} }
type completeLogger struct { type completeLogger struct {
print, debug, error, fatal, info, warn func(v ...interface{}) print, debug, error, fatal, info, warn func(v ...any)
printf, debugf, errorf, fatalf, infof, warnf func(format string, v ...interface{}) printf, debugf, errorf, fatalf, infof, warnf func(format string, v ...any)
debugC, errorC, fatalC, infoC, warnC func(ctx context.Context, v ...interface{}) debugC, errorC, fatalC, infoC, warnC func(ctx context.Context, v ...any)
debugCf, errorCf, fatalCf, infoCf, warnCf func(ctx context.Context, format string, v ...interface{}) debugCf, errorCf, fatalCf, infoCf, warnCf func(ctx context.Context, format string, v ...any)
write func(l LoggerLevel, v ...interface{}) write func(l LoggerLevel, v ...any)
writeC func(ctx context.Context, l LoggerLevel, v ...interface{}) writeC func(ctx context.Context, l LoggerLevel, v ...any)
writeCf func(ctx context.Context, l LoggerLevel, format string, v ...interface{}) writeCf func(ctx context.Context, l LoggerLevel, format string, v ...any)
writef func(l LoggerLevel, format string, v ...interface{}) writef func(l LoggerLevel, format string, v ...any)
} }
func newCompleteLogger() *completeLogger { func newCompleteLogger() *completeLogger {
l := &completeLogger{} l := &completeLogger{}
l.debug = func(v ...interface{}) { l.print(v...) } l.debug = func(v ...any) { l.print(v...) }
l.debugf = func(format string, v ...interface{}) { l.printf(format, v...) } l.debugf = func(format string, v ...any) { l.printf(format, v...) }
l.debugC = func(ctx context.Context, v ...interface{}) { l.debug(v...) } l.debugC = func(ctx context.Context, v ...any) { l.debug(v...) }
l.debugCf = func(ctx context.Context, format string, v ...interface{}) { l.debugf(format, v...) } l.debugCf = func(ctx context.Context, format string, v ...any) { l.debugf(format, v...) }
l.error = func(v ...interface{}) { l.print(v...) } l.error = func(v ...any) { l.print(v...) }
l.errorf = func(format string, v ...interface{}) { l.printf(format, v...) } l.errorf = func(format string, v ...any) { l.printf(format, v...) }
l.errorC = func(ctx context.Context, v ...interface{}) { l.error(v...) } l.errorC = func(ctx context.Context, v ...any) { l.error(v...) }
l.errorCf = func(ctx context.Context, format string, v ...interface{}) { l.errorf(format, v...) } l.errorCf = func(ctx context.Context, format string, v ...any) { l.errorf(format, v...) }
l.fatal = func(v ...interface{}) { l.print(v...) } l.fatal = func(v ...any) { l.print(v...) }
l.fatalf = func(format string, v ...interface{}) { l.printf(format, v...) } l.fatalf = func(format string, v ...any) { l.printf(format, v...) }
l.fatalC = func(ctx context.Context, v ...interface{}) { l.fatal(v...) } l.fatalC = func(ctx context.Context, v ...any) { l.fatal(v...) }
l.fatalCf = func(ctx context.Context, format string, v ...interface{}) { l.fatalf(format, v...) } l.fatalCf = func(ctx context.Context, format string, v ...any) { l.fatalf(format, v...) }
l.info = func(v ...interface{}) { l.print(v...) } l.info = func(v ...any) { l.print(v...) }
l.infof = func(format string, v ...interface{}) { l.printf(format, v...) } l.infof = func(format string, v ...any) { l.printf(format, v...) }
l.infoC = func(ctx context.Context, v ...interface{}) { l.info(v...) } l.infoC = func(ctx context.Context, v ...any) { l.info(v...) }
l.infoCf = func(ctx context.Context, format string, v ...interface{}) { l.infof(format, v...) } l.infoCf = func(ctx context.Context, format string, v ...any) { l.infof(format, v...) }
l.print = func(v ...interface{}) {} l.print = func(v ...any) {}
l.printf = func(format string, v ...interface{}) {} l.printf = func(format string, v ...any) {}
l.warn = func(v ...interface{}) { l.print(v...) } l.warn = func(v ...any) { l.print(v...) }
l.warnf = func(format string, v ...interface{}) { l.printf(format, v...) } l.warnf = func(format string, v ...any) { l.printf(format, v...) }
l.warnC = func(ctx context.Context, v ...interface{}) { l.warn(v...) } l.warnC = func(ctx context.Context, v ...any) { l.warn(v...) }
l.warnCf = func(ctx context.Context, format string, v ...interface{}) { l.warnf(format, v...) } l.warnCf = func(ctx context.Context, format string, v ...any) { l.warnf(format, v...) }
l.write = func(lv LoggerLevel, v ...interface{}) { l.write = func(lv LoggerLevel, v ...any) {
switch lv { switch lv {
case LoggerLevelDebug: case LoggerLevelDebug:
l.debug(v...) l.debug(v...)
@@ -168,7 +168,7 @@ func newCompleteLogger() *completeLogger {
l.info(v...) 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 { switch lv {
case LoggerLevelDebug: case LoggerLevelDebug:
l.debugC(ctx, v...) l.debugC(ctx, v...)
@@ -182,7 +182,7 @@ func newCompleteLogger() *completeLogger {
l.infoC(ctx, v...) 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 { switch lv {
case LoggerLevelDebug: case LoggerLevelDebug:
l.debugCf(ctx, format, v...) l.debugCf(ctx, format, v...)
@@ -196,7 +196,7 @@ func newCompleteLogger() *completeLogger {
l.infoCf(ctx, format, v...) 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 { switch lv {
case LoggerLevelDebug: case LoggerLevelDebug:
l.debugf(format, v...) l.debugf(format, v...)
@@ -213,46 +213,46 @@ func newCompleteLogger() *completeLogger {
return l return l
} }
func (l *completeLogger) Debug(v ...interface{}) { l.debug(v...) } func (l *completeLogger) Debug(v ...any) { l.debug(v...) }
func (l *completeLogger) Debugf(format string, v ...interface{}) { l.debugf(format, v...) } func (l *completeLogger) Debugf(format string, v ...any) { l.debugf(format, v...) }
func (l *completeLogger) DebugC(ctx context.Context, v ...interface{}) { l.debugC(ctx, v...) } func (l *completeLogger) DebugC(ctx context.Context, v ...any) { l.debugC(ctx, v...) }
func (l *completeLogger) DebugCf(ctx context.Context, format string, v ...interface{}) { func (l *completeLogger) DebugCf(ctx context.Context, format string, v ...any) {
l.debugCf(ctx, format, v...) l.debugCf(ctx, format, v...)
} }
func (l *completeLogger) Error(v ...interface{}) { l.error(v...) } func (l *completeLogger) Error(v ...any) { l.error(v...) }
func (l *completeLogger) Errorf(format string, v ...interface{}) { l.errorf(format, v...) } func (l *completeLogger) Errorf(format string, v ...any) { l.errorf(format, v...) }
func (l *completeLogger) ErrorC(ctx context.Context, v ...interface{}) { l.errorC(ctx, v...) } func (l *completeLogger) ErrorC(ctx context.Context, v ...any) { l.errorC(ctx, v...) }
func (l *completeLogger) ErrorCf(ctx context.Context, format string, v ...interface{}) { func (l *completeLogger) ErrorCf(ctx context.Context, format string, v ...any) {
l.errorCf(ctx, format, v...) l.errorCf(ctx, format, v...)
} }
func (l *completeLogger) Fatal(v ...interface{}) { l.fatal(v...) } func (l *completeLogger) Fatal(v ...any) { l.fatal(v...) }
func (l *completeLogger) Fatalf(format string, v ...interface{}) { l.fatalf(format, v...) } func (l *completeLogger) Fatalf(format string, v ...any) { l.fatalf(format, v...) }
func (l *completeLogger) FatalC(ctx context.Context, v ...interface{}) { l.fatalC(ctx, v...) } func (l *completeLogger) FatalC(ctx context.Context, v ...any) { l.fatalC(ctx, v...) }
func (l *completeLogger) FatalCf(ctx context.Context, format string, v ...interface{}) { func (l *completeLogger) FatalCf(ctx context.Context, format string, v ...any) {
l.fatalCf(ctx, format, v...) l.fatalCf(ctx, format, v...)
} }
func (l *completeLogger) Info(v ...interface{}) { l.info(v...) } func (l *completeLogger) Info(v ...any) { l.info(v...) }
func (l *completeLogger) Infof(format string, v ...interface{}) { l.infof(format, v...) } func (l *completeLogger) Infof(format string, v ...any) { l.infof(format, v...) }
func (l *completeLogger) InfoC(ctx context.Context, v ...interface{}) { l.infoC(ctx, v...) } func (l *completeLogger) InfoC(ctx context.Context, v ...any) { l.infoC(ctx, v...) }
func (l *completeLogger) InfoCf(ctx context.Context, format string, v ...interface{}) { func (l *completeLogger) InfoCf(ctx context.Context, format string, v ...any) {
l.infoCf(ctx, format, v...) l.infoCf(ctx, format, v...)
} }
func (l *completeLogger) Print(v ...interface{}) { l.print(v...) } func (l *completeLogger) Print(v ...any) { l.print(v...) }
func (l *completeLogger) Printf(format string, v ...interface{}) { l.printf(format, v...) } func (l *completeLogger) Printf(format string, v ...any) { l.printf(format, v...) }
func (l *completeLogger) Warn(v ...interface{}) { l.warn(v...) } func (l *completeLogger) Warn(v ...any) { l.warn(v...) }
func (l *completeLogger) Warnf(format string, v ...interface{}) { l.warnf(format, v...) } func (l *completeLogger) Warnf(format string, v ...any) { l.warnf(format, v...) }
func (l *completeLogger) WarnC(ctx context.Context, v ...interface{}) { l.warnC(ctx, v...) } func (l *completeLogger) WarnC(ctx context.Context, v ...any) { l.warnC(ctx, v...) }
func (l *completeLogger) WarnCf(ctx context.Context, format string, v ...interface{}) { func (l *completeLogger) WarnCf(ctx context.Context, format string, v ...any) {
l.warnCf(ctx, format, v...) l.warnCf(ctx, format, v...)
} }
func (l *completeLogger) Write(lv LoggerLevel, v ...interface{}) { l.write(lv, v...) } func (l *completeLogger) Write(lv LoggerLevel, v ...any) { l.write(lv, v...) }
func (l *completeLogger) Writef(lv LoggerLevel, format string, v ...interface{}) { func (l *completeLogger) Writef(lv LoggerLevel, format string, v ...any) {
l.writef(lv, format, v...) 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...) 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...) l.writeCf(ctx, lv, format, v...)
} }
+12 -12
View File
@@ -7,21 +7,21 @@ import (
// BiMap represents a bidirectional map // BiMap represents a bidirectional map
type BiMap struct { type BiMap struct {
forward map[interface{}]interface{} forward map[any]any
inverse map[interface{}]interface{} inverse map[any]any
m *sync.Mutex m *sync.Mutex
} }
// NewBiMap creates a new BiMap // NewBiMap creates a new BiMap
func NewBiMap() *BiMap { func NewBiMap() *BiMap {
return &BiMap{ return &BiMap{
forward: make(map[interface{}]interface{}), forward: make(map[any]any),
inverse: make(map[interface{}]interface{}), inverse: make(map[any]any),
m: &sync.Mutex{}, 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() m.m.Lock()
defer m.m.Unlock() defer m.m.Unlock()
v, ok = i[k] 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 // 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 // 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 // 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) v, ok := m.get(k, m.forward)
if !ok { if !ok {
panic(fmt.Sprintf("astikit: key %+v not found in foward map", k)) 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 // 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) v, ok := m.get(k, m.inverse)
if !ok { if !ok {
panic(fmt.Sprintf("astikit: key %+v not found in inverse map", k)) 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 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() m.m.Lock()
defer m.m.Unlock() defer m.m.Unlock()
f[k] = v 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 // 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 // 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) }
+9 -9
View File
@@ -22,7 +22,7 @@ type Stater struct {
type StatOptions struct { type StatOptions struct {
Metadata *StatMetadata Metadata *StatMetadata
// Either a StatValuer or StatValuerOverTime // Either a StatValuer or StatValuerOverTime
Valuer interface{} Valuer any
} }
// StatsHandleFunc is a method that can handle stat values // StatsHandleFunc is a method that can handle stat values
@@ -38,19 +38,19 @@ type StatMetadata struct {
// StatValuer represents a stat valuer // StatValuer represents a stat valuer
type StatValuer interface { 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) return f(d)
} }
// StatValue represents a stat value // StatValue represents a stat value
type StatValue struct { type StatValue struct {
*StatMetadata *StatMetadata
Value interface{} Value any
} }
// StaterOptions represents stater options // StaterOptions represents stater options
@@ -103,7 +103,7 @@ func (s *Stater) Start(ctx context.Context) {
s.m.Lock() s.m.Lock()
for _, o := range s.ss { for _, o := range s.ss {
// Get value // Get value
var v interface{} var v any
if h, ok := o.Valuer.(StatValuer); ok { if h, ok := o.Valuer.(StatValuer); ok {
v = h.Value(delta) v = h.Value(delta)
} else { } else {
@@ -161,7 +161,7 @@ func NewAtomicUint64RateStat(v *uint64) *AtomicUint64RateStat {
return &AtomicUint64RateStat{v: v} 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) current := atomic.LoadUint64(s.v)
defer func() { s.last = &current }() defer func() { s.last = &current }()
if d <= 0 { if d <= 0 {
@@ -183,7 +183,7 @@ func NewAtomicDurationPercentageStat(d *AtomicDuration) *AtomicDurationPercentag
return &AtomicDurationPercentageStat{d: d} return &AtomicDurationPercentageStat{d: d}
} }
func (s *AtomicDurationPercentageStat) Value(d time.Duration) interface{} { func (s *AtomicDurationPercentageStat) Value(d time.Duration) any {
current := s.d.Duration() current := s.d.Duration()
defer func() { s.last = &current }() defer func() { s.last = &current }()
if d <= 0 { 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() current := s.d.Duration()
currentCount := atomic.LoadUint64(s.count) currentCount := atomic.LoadUint64(s.count)
defer func() { defer func() {
+1 -1
View File
@@ -36,7 +36,7 @@ func TestStater(t *testing.T) {
v3 := NewAtomicDurationAvgStat(d3, &u1) v3 := NewAtomicDurationAvgStat(d3, &u1)
m3 := &StatMetadata{Description: "3"} m3 := &StatMetadata{Description: "3"}
o3 := StatOptions{Metadata: m3, Valuer: v3} 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"} m4 := &StatMetadata{Description: "4"}
o4 := StatOptions{Metadata: m4, Valuer: v4} o4 := StatOptions{Metadata: m4, Valuer: v4}
+4 -4
View File
@@ -231,7 +231,7 @@ type BufferPool struct {
// NewBufferPool creates a new BufferPool // NewBufferPool creates a new BufferPool
func NewBufferPool() *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 // New creates a new BufferPoolItem
@@ -359,7 +359,7 @@ type EventerOptions struct {
} }
// EventerHandler represents a function that can handle the payload of an event // 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 // NewEventer creates a new eventer
func NewEventer(o EventerOptions) *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 // 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 // Lock
e.mh.Lock() e.mh.Lock()
defer e.mh.Unlock() defer e.mh.Unlock()
@@ -468,7 +468,7 @@ func (m *DebugMutex) caller() (o string) {
return return
} }
func (m *DebugMutex) log(fmt string, args ...interface{}) { func (m *DebugMutex) log(fmt string, args ...any) {
if m.ll < LoggerLevelDebug { if m.ll < LoggerLevelDebug {
return return
} }
+6 -6
View File
@@ -129,8 +129,8 @@ func TestGoroutineLimiter(t *testing.T) {
func TestEventer(t *testing.T) { func TestEventer(t *testing.T) {
e := NewEventer(EventerOptions{Chan: ChanOptions{ProcessAll: true}}) e := NewEventer(EventerOptions{Chan: ChanOptions{ProcessAll: true}})
var o []string var o []string
e.On("1", func(payload interface{}) { o = append(o, payload.(string)) }) e.On("1", func(payload any) { o = append(o, payload.(string)) })
e.On("2", func(payload interface{}) { o = append(o, payload.(string)) }) e.On("2", func(payload any) { o = append(o, payload.(string)) })
go func() { go func() {
time.Sleep(10 * time.Millisecond) time.Sleep(10 * time.Millisecond)
e.Dispatch("1", "1.1") e.Dispatch("1", "1.1")
@@ -149,22 +149,22 @@ type mockedStdLogger struct {
ss []string ss []string
} }
func (l *mockedStdLogger) Fatal(v ...interface{}) { func (l *mockedStdLogger) Fatal(v ...any) {
l.m.Lock() l.m.Lock()
defer l.m.Unlock() defer l.m.Unlock()
l.ss = append(l.ss, "fatal: "+fmt.Sprint(v...)) 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() l.m.Lock()
defer l.m.Unlock() defer l.m.Unlock()
l.ss = append(l.ss, "fatal: "+fmt.Sprintf(format, v...)) 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() l.m.Lock()
defer l.m.Unlock() defer l.m.Unlock()
l.ss = append(l.ss, "print: "+fmt.Sprint(v...)) 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() l.m.Lock()
defer l.m.Unlock() defer l.m.Unlock()
l.ss = append(l.ss, "print: "+fmt.Sprintf(format, v...)) l.ss = append(l.ss, "print: "+fmt.Sprintf(format, v...))
+5 -5
View File
@@ -101,7 +101,7 @@ func (t *Translator) ParseFile(dirPath, path string) (err error) {
defer f.Close() defer f.Close()
// Unmarshal // Unmarshal
var p map[string]interface{} var p map[string]any
if err = json.NewDecoder(f).Decode(&p); err != nil { if err = json.NewDecoder(f).Decode(&p); err != nil {
err = fmt.Errorf("astikit: unmarshaling %s failed: %w", path, err) err = fmt.Errorf("astikit: unmarshaling %s failed: %w", path, err)
return return
@@ -134,13 +134,13 @@ func (t *Translator) key(prefix, key string) string {
return prefix + "." + key 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 { for k, v := range i {
p := t.key(prefix, k) p := t.key(prefix, k)
switch a := v.(type) { switch a := v.(type) {
case string: case string:
t.p[p] = a t.p[p] = a
case map[string]interface{}: case map[string]any:
t.parse(a, p) 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 // 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...) 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) 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...) return t.Translatef(translatorLanguageFromContext(ctx), key, args...)
} }
+1 -1
View File
@@ -31,7 +31,7 @@ func TestTranslator(t *testing.T) {
// Middleware // Middleware
var o string var o string
s := httptest.NewServer(ChainHTTPMiddlewares(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { 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 != "" { if v := r.Header.Get("args"); v != "" {
for _, s := range strings.Split(v, ",") { for _, s := range strings.Split(v, ",") {
args = append(args, s) args = append(args, s)