mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
Run modernize (#21546)
`go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...` executed. `go generate ./...` ran afterwards to keep generated.
This commit is contained in:
@@ -60,7 +60,7 @@ func GetAuditEntry(ctx context.Context) *audit.Entry {
|
||||
}
|
||||
|
||||
// AuditLog - logs audit logs to all audit targets.
|
||||
func AuditLog(ctx context.Context, w http.ResponseWriter, r *http.Request, reqClaims map[string]interface{}, filterKeys ...string) {
|
||||
func AuditLog(ctx context.Context, w http.ResponseWriter, r *http.Request, reqClaims map[string]any, filterKeys ...string) {
|
||||
auditTgts := AuditTargets()
|
||||
if len(auditTgts) == 0 {
|
||||
return
|
||||
@@ -124,7 +124,7 @@ func AuditLog(ctx context.Context, w http.ResponseWriter, r *http.Request, reqCl
|
||||
entry.API.TimeToResponse = strconv.FormatInt(timeToResponse.Nanoseconds(), 10) + "ns"
|
||||
entry.API.TimeToResponseInNS = strconv.FormatInt(timeToResponse.Nanoseconds(), 10)
|
||||
// We hold the lock, so we cannot call reqInfo.GetTagsMap().
|
||||
tags := make(map[string]interface{}, len(reqInfo.tags))
|
||||
tags := make(map[string]any, len(reqInfo.tags))
|
||||
for _, t := range reqInfo.tags {
|
||||
tags[t.Key] = t.Val
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ func lookupAuditKafkaConfig(scfg config.Config, cfg Config) (Config, error) {
|
||||
if len(kafkaBrokers) == 0 {
|
||||
return cfg, config.Errorf("kafka 'brokers' cannot be empty")
|
||||
}
|
||||
for _, s := range strings.Split(kafkaBrokers, config.ValueSeparator) {
|
||||
for s := range strings.SplitSeq(kafkaBrokers, config.ValueSeparator) {
|
||||
var host *xnet.Host
|
||||
host, err = xnet.ParseHost(s)
|
||||
if err != nil {
|
||||
|
||||
@@ -36,12 +36,12 @@ var ExitFunc = os.Exit
|
||||
|
||||
// Logger interface describes the methods that need to be implemented to satisfy the interface requirements.
|
||||
type Logger interface {
|
||||
json(msg string, args ...interface{})
|
||||
quiet(msg string, args ...interface{})
|
||||
pretty(msg string, args ...interface{})
|
||||
json(msg string, args ...any)
|
||||
quiet(msg string, args ...any)
|
||||
pretty(msg string, args ...any)
|
||||
}
|
||||
|
||||
func consoleLog(console Logger, msg string, args ...interface{}) {
|
||||
func consoleLog(console Logger, msg string, args ...any) {
|
||||
switch {
|
||||
case jsonFlag:
|
||||
// Strip escape control characters from json message
|
||||
@@ -64,11 +64,11 @@ func consoleLog(console Logger, msg string, args ...interface{}) {
|
||||
|
||||
// Fatal prints only fatal error message with no stack trace
|
||||
// it will be called for input validation failures
|
||||
func Fatal(err error, msg string, data ...interface{}) {
|
||||
func Fatal(err error, msg string, data ...any) {
|
||||
fatal(err, msg, data...)
|
||||
}
|
||||
|
||||
func fatal(err error, msg string, data ...interface{}) {
|
||||
func fatal(err error, msg string, data ...any) {
|
||||
if msg == "" {
|
||||
if len(data) > 0 {
|
||||
msg = fmt.Sprint(data...)
|
||||
@@ -85,7 +85,7 @@ var fatalMessage fatalMsg
|
||||
|
||||
type fatalMsg struct{}
|
||||
|
||||
func (f fatalMsg) json(msg string, args ...interface{}) {
|
||||
func (f fatalMsg) json(msg string, args ...any) {
|
||||
var message string
|
||||
if msg != "" {
|
||||
message = fmt.Sprintf(msg, args...)
|
||||
@@ -105,7 +105,7 @@ func (f fatalMsg) json(msg string, args ...interface{}) {
|
||||
ExitFunc(1)
|
||||
}
|
||||
|
||||
func (f fatalMsg) quiet(msg string, args ...interface{}) {
|
||||
func (f fatalMsg) quiet(msg string, args ...any) {
|
||||
f.pretty(msg, args...)
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ var (
|
||||
bannerWidth = len(logTag) + 1
|
||||
)
|
||||
|
||||
func (f fatalMsg) pretty(msg string, args ...interface{}) {
|
||||
func (f fatalMsg) pretty(msg string, args ...any) {
|
||||
// Build the passed error message
|
||||
errMsg := fmt.Sprintf(msg, args...)
|
||||
|
||||
@@ -128,30 +128,27 @@ func (f fatalMsg) pretty(msg string, args ...interface{}) {
|
||||
// message itself contains some colored text, we needed
|
||||
// to use some ANSI control escapes to cursor color state
|
||||
// and freely move in the screen.
|
||||
for _, line := range strings.Split(errMsg, "\n") {
|
||||
for line := range strings.SplitSeq(errMsg, "\n") {
|
||||
if len(line) == 0 {
|
||||
// No more text to print, just quit.
|
||||
break
|
||||
}
|
||||
|
||||
for {
|
||||
// Save the attributes of the current cursor helps
|
||||
// us save the text color of the passed error message
|
||||
ansiSaveAttributes()
|
||||
// Print banner with or without the log tag
|
||||
if !tagPrinted {
|
||||
fmt.Fprint(Output, logBanner)
|
||||
tagPrinted = true
|
||||
} else {
|
||||
fmt.Fprint(Output, emptyBanner)
|
||||
}
|
||||
// Restore the text color of the error message
|
||||
ansiRestoreAttributes()
|
||||
ansiMoveRight(bannerWidth)
|
||||
// Continue error message printing
|
||||
fmt.Fprintln(Output, line)
|
||||
break
|
||||
// Save the attributes of the current cursor helps
|
||||
// us save the text color of the passed error message
|
||||
ansiSaveAttributes()
|
||||
// Print banner with or without the log tag
|
||||
if !tagPrinted {
|
||||
fmt.Fprint(Output, logBanner)
|
||||
tagPrinted = true
|
||||
} else {
|
||||
fmt.Fprint(Output, emptyBanner)
|
||||
}
|
||||
// Restore the text color of the error message
|
||||
ansiRestoreAttributes()
|
||||
ansiMoveRight(bannerWidth)
|
||||
// Continue error message printing
|
||||
fmt.Fprintln(Output, line)
|
||||
}
|
||||
|
||||
// Exit because this is a fatal error message
|
||||
@@ -162,7 +159,7 @@ type infoMsg struct{}
|
||||
|
||||
var info infoMsg
|
||||
|
||||
func (i infoMsg) json(msg string, args ...interface{}) {
|
||||
func (i infoMsg) json(msg string, args ...any) {
|
||||
var message string
|
||||
if msg != "" {
|
||||
message = fmt.Sprintf(msg, args...)
|
||||
@@ -180,10 +177,10 @@ func (i infoMsg) json(msg string, args ...interface{}) {
|
||||
fmt.Fprintln(Output, string(logJSON))
|
||||
}
|
||||
|
||||
func (i infoMsg) quiet(msg string, args ...interface{}) {
|
||||
func (i infoMsg) quiet(msg string, args ...any) {
|
||||
}
|
||||
|
||||
func (i infoMsg) pretty(msg string, args ...interface{}) {
|
||||
func (i infoMsg) pretty(msg string, args ...any) {
|
||||
if msg == "" {
|
||||
fmt.Fprintln(Output, args...)
|
||||
} else {
|
||||
@@ -195,7 +192,7 @@ type errorMsg struct{}
|
||||
|
||||
var errorMessage errorMsg
|
||||
|
||||
func (i errorMsg) json(msg string, args ...interface{}) {
|
||||
func (i errorMsg) json(msg string, args ...any) {
|
||||
var message string
|
||||
if msg != "" {
|
||||
message = fmt.Sprintf(msg, args...)
|
||||
@@ -214,11 +211,11 @@ func (i errorMsg) json(msg string, args ...interface{}) {
|
||||
fmt.Fprintln(Output, string(logJSON))
|
||||
}
|
||||
|
||||
func (i errorMsg) quiet(msg string, args ...interface{}) {
|
||||
func (i errorMsg) quiet(msg string, args ...any) {
|
||||
i.pretty(msg, args...)
|
||||
}
|
||||
|
||||
func (i errorMsg) pretty(msg string, args ...interface{}) {
|
||||
func (i errorMsg) pretty(msg string, args ...any) {
|
||||
if msg == "" {
|
||||
fmt.Fprintln(Output, args...)
|
||||
} else {
|
||||
@@ -227,7 +224,7 @@ func (i errorMsg) pretty(msg string, args ...interface{}) {
|
||||
}
|
||||
|
||||
// Error :
|
||||
func Error(msg string, data ...interface{}) {
|
||||
func Error(msg string, data ...any) {
|
||||
if DisableLog {
|
||||
return
|
||||
}
|
||||
@@ -235,7 +232,7 @@ func Error(msg string, data ...interface{}) {
|
||||
}
|
||||
|
||||
// Info :
|
||||
func Info(msg string, data ...interface{}) {
|
||||
func Info(msg string, data ...any) {
|
||||
if DisableLog {
|
||||
return
|
||||
}
|
||||
@@ -243,7 +240,7 @@ func Info(msg string, data ...interface{}) {
|
||||
}
|
||||
|
||||
// Startup :
|
||||
func Startup(msg string, data ...interface{}) {
|
||||
func Startup(msg string, data ...any) {
|
||||
if DisableLog {
|
||||
return
|
||||
}
|
||||
@@ -254,7 +251,7 @@ type startupMsg struct{}
|
||||
|
||||
var startup startupMsg
|
||||
|
||||
func (i startupMsg) json(msg string, args ...interface{}) {
|
||||
func (i startupMsg) json(msg string, args ...any) {
|
||||
var message string
|
||||
if msg != "" {
|
||||
message = fmt.Sprintf(msg, args...)
|
||||
@@ -272,10 +269,10 @@ func (i startupMsg) json(msg string, args ...interface{}) {
|
||||
fmt.Fprintln(Output, string(logJSON))
|
||||
}
|
||||
|
||||
func (i startupMsg) quiet(msg string, args ...interface{}) {
|
||||
func (i startupMsg) quiet(msg string, args ...any) {
|
||||
}
|
||||
|
||||
func (i startupMsg) pretty(msg string, args ...interface{}) {
|
||||
func (i startupMsg) pretty(msg string, args ...any) {
|
||||
if msg == "" {
|
||||
fmt.Fprintln(Output, args...)
|
||||
} else {
|
||||
@@ -287,7 +284,7 @@ type warningMsg struct{}
|
||||
|
||||
var warningMessage warningMsg
|
||||
|
||||
func (i warningMsg) json(msg string, args ...interface{}) {
|
||||
func (i warningMsg) json(msg string, args ...any) {
|
||||
var message string
|
||||
if msg != "" {
|
||||
message = fmt.Sprintf(msg, args...)
|
||||
@@ -306,11 +303,11 @@ func (i warningMsg) json(msg string, args ...interface{}) {
|
||||
fmt.Fprintln(Output, string(logJSON))
|
||||
}
|
||||
|
||||
func (i warningMsg) quiet(msg string, args ...interface{}) {
|
||||
func (i warningMsg) quiet(msg string, args ...any) {
|
||||
i.pretty(msg, args...)
|
||||
}
|
||||
|
||||
func (i warningMsg) pretty(msg string, args ...interface{}) {
|
||||
func (i warningMsg) pretty(msg string, args ...any) {
|
||||
if msg == "" {
|
||||
fmt.Fprintln(Output, args...)
|
||||
} else {
|
||||
@@ -319,7 +316,7 @@ func (i warningMsg) pretty(msg string, args ...interface{}) {
|
||||
}
|
||||
|
||||
// Warning :
|
||||
func Warning(msg string, data ...interface{}) {
|
||||
func Warning(msg string, data ...any) {
|
||||
if DisableLog {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ func HashString(input string) string {
|
||||
|
||||
// LogAlwaysIf prints a detailed error message during
|
||||
// the execution of the server.
|
||||
func LogAlwaysIf(ctx context.Context, subsystem string, err error, errKind ...interface{}) {
|
||||
func LogAlwaysIf(ctx context.Context, subsystem string, err error, errKind ...any) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
@@ -264,7 +264,7 @@ func LogAlwaysIf(ctx context.Context, subsystem string, err error, errKind ...in
|
||||
// LogIf prints a detailed error message during
|
||||
// the execution of the server, if it is not an
|
||||
// ignored error.
|
||||
func LogIf(ctx context.Context, subsystem string, err error, errKind ...interface{}) {
|
||||
func LogIf(ctx context.Context, subsystem string, err error, errKind ...any) {
|
||||
if logIgnoreError(err) {
|
||||
return
|
||||
}
|
||||
@@ -285,7 +285,7 @@ func LogIfNot(ctx context.Context, subsystem string, err error, ignored ...error
|
||||
logIf(ctx, subsystem, err)
|
||||
}
|
||||
|
||||
func errToEntry(ctx context.Context, subsystem string, err error, errKind ...interface{}) log.Entry {
|
||||
func errToEntry(ctx context.Context, subsystem string, err error, errKind ...any) log.Entry {
|
||||
var l string
|
||||
if anonFlag {
|
||||
l = reflect.TypeOf(err).String()
|
||||
@@ -295,11 +295,11 @@ func errToEntry(ctx context.Context, subsystem string, err error, errKind ...int
|
||||
return buildLogEntry(ctx, subsystem, l, getTrace(3), errKind...)
|
||||
}
|
||||
|
||||
func logToEntry(ctx context.Context, subsystem, message string, errKind ...interface{}) log.Entry {
|
||||
func logToEntry(ctx context.Context, subsystem, message string, errKind ...any) log.Entry {
|
||||
return buildLogEntry(ctx, subsystem, message, nil, errKind...)
|
||||
}
|
||||
|
||||
func buildLogEntry(ctx context.Context, subsystem, message string, trace []string, errKind ...interface{}) log.Entry {
|
||||
func buildLogEntry(ctx context.Context, subsystem, message string, trace []string, errKind ...any) log.Entry {
|
||||
logKind := madmin.LogKindError
|
||||
if len(errKind) > 0 {
|
||||
if ek, ok := errKind[0].(madmin.LogKind); ok {
|
||||
@@ -326,7 +326,7 @@ func buildLogEntry(ctx context.Context, subsystem, message string, trace []strin
|
||||
}
|
||||
|
||||
// Copy tags. We hold read lock already.
|
||||
tags := make(map[string]interface{}, len(req.tags))
|
||||
tags := make(map[string]any, len(req.tags))
|
||||
for _, entry := range req.tags {
|
||||
tags[entry.Key] = entry.Val
|
||||
}
|
||||
@@ -379,7 +379,7 @@ func buildLogEntry(ctx context.Context, subsystem, message string, trace []strin
|
||||
entry.API.Args.Object = HashString(entry.API.Args.Object)
|
||||
entry.RemoteHost = HashString(entry.RemoteHost)
|
||||
if entry.Trace != nil {
|
||||
entry.Trace.Variables = make(map[string]interface{})
|
||||
entry.Trace.Variables = make(map[string]any)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,7 +388,7 @@ func buildLogEntry(ctx context.Context, subsystem, message string, trace []strin
|
||||
|
||||
// consoleLogIf prints a detailed error message during
|
||||
// the execution of the server.
|
||||
func consoleLogIf(ctx context.Context, subsystem string, err error, errKind ...interface{}) {
|
||||
func consoleLogIf(ctx context.Context, subsystem string, err error, errKind ...any) {
|
||||
if DisableLog {
|
||||
return
|
||||
}
|
||||
@@ -403,7 +403,7 @@ func consoleLogIf(ctx context.Context, subsystem string, err error, errKind ...i
|
||||
|
||||
// logIf prints a detailed error message during
|
||||
// the execution of the server.
|
||||
func logIf(ctx context.Context, subsystem string, err error, errKind ...interface{}) {
|
||||
func logIf(ctx context.Context, subsystem string, err error, errKind ...any) {
|
||||
if DisableLog {
|
||||
return
|
||||
}
|
||||
@@ -431,7 +431,7 @@ func sendLog(ctx context.Context, entry log.Entry) {
|
||||
}
|
||||
|
||||
// Event sends a event log to log targets
|
||||
func Event(ctx context.Context, subsystem, msg string, args ...interface{}) {
|
||||
func Event(ctx context.Context, subsystem, msg string, args ...any) {
|
||||
if DisableLog {
|
||||
return
|
||||
}
|
||||
@@ -444,7 +444,7 @@ var ErrCritical struct{}
|
||||
|
||||
// CriticalIf logs the provided error on the console. It fails the
|
||||
// current go-routine by causing a `panic(ErrCritical)`.
|
||||
func CriticalIf(ctx context.Context, err error, errKind ...interface{}) {
|
||||
func CriticalIf(ctx context.Context, err error, errKind ...any) {
|
||||
if err != nil {
|
||||
LogIf(ctx, "", err, errKind...)
|
||||
panic(ErrCritical)
|
||||
@@ -452,7 +452,7 @@ func CriticalIf(ctx context.Context, err error, errKind ...interface{}) {
|
||||
}
|
||||
|
||||
// FatalIf is similar to Fatal() but it ignores passed nil error
|
||||
func FatalIf(err error, msg string, data ...interface{}) {
|
||||
func FatalIf(err error, msg string, data ...any) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
)
|
||||
|
||||
// LogOnce provides the function type for logger.LogOnceIf() function
|
||||
type LogOnce func(ctx context.Context, err error, id string, errKind ...interface{})
|
||||
type LogOnce func(ctx context.Context, err error, id string, errKind ...any)
|
||||
|
||||
type onceErr struct {
|
||||
Err error
|
||||
@@ -38,7 +38,7 @@ type logOnceType struct {
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
func (l *logOnceType) logOnceConsoleIf(ctx context.Context, subsystem string, err error, id string, errKind ...interface{}) {
|
||||
func (l *logOnceType) logOnceConsoleIf(ctx context.Context, subsystem string, err error, id string, errKind ...any) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
@@ -92,7 +92,7 @@ func unwrapErrs(err error) (leafErr error) {
|
||||
}
|
||||
|
||||
// One log message per error.
|
||||
func (l *logOnceType) logOnceIf(ctx context.Context, subsystem string, err error, id string, errKind ...interface{}) {
|
||||
func (l *logOnceType) logOnceIf(ctx context.Context, subsystem string, err error, id string, errKind ...any) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
@@ -142,7 +142,7 @@ var logOnce = newLogOnceType()
|
||||
// LogOnceIf - Logs notification errors - once per error.
|
||||
// id is a unique identifier for related log messages, refer to cmd/notification.go
|
||||
// on how it is used.
|
||||
func LogOnceIf(ctx context.Context, subsystem string, err error, id string, errKind ...interface{}) {
|
||||
func LogOnceIf(ctx context.Context, subsystem string, err error, id string, errKind ...any) {
|
||||
if logIgnoreError(err) {
|
||||
return
|
||||
}
|
||||
@@ -150,7 +150,7 @@ func LogOnceIf(ctx context.Context, subsystem string, err error, id string, errK
|
||||
}
|
||||
|
||||
// LogOnceConsoleIf - similar to LogOnceIf but exclusively only logs to console target.
|
||||
func LogOnceConsoleIf(ctx context.Context, subsystem string, err error, id string, errKind ...interface{}) {
|
||||
func LogOnceConsoleIf(ctx context.Context, subsystem string, err error, id string, errKind ...any) {
|
||||
if logIgnoreError(err) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func NewEntry(deploymentID string) audit.Entry {
|
||||
}
|
||||
|
||||
// ToEntry - constructs an audit entry from a http request
|
||||
func ToEntry(w http.ResponseWriter, r *http.Request, reqClaims map[string]interface{}, deploymentID string) audit.Entry {
|
||||
func ToEntry(w http.ResponseWriter, r *http.Request, reqClaims map[string]any, deploymentID string) audit.Entry {
|
||||
entry := NewEntry(deploymentID)
|
||||
|
||||
entry.RemoteHost = handlers.GetSourceIP(r)
|
||||
|
||||
@@ -50,7 +50,7 @@ func (c *Target) String() string {
|
||||
}
|
||||
|
||||
// Send log message 'e' to console
|
||||
func (c *Target) Send(e interface{}) error {
|
||||
func (c *Target) Send(e any) error {
|
||||
entry, ok := e.(log.Entry)
|
||||
if !ok {
|
||||
return fmt.Errorf("Uexpected log entry structure %#v", e)
|
||||
|
||||
@@ -61,7 +61,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
logChBuffers = make(map[string]chan interface{})
|
||||
logChBuffers = make(map[string]chan any)
|
||||
logChLock = sync.Mutex{}
|
||||
)
|
||||
|
||||
@@ -84,7 +84,7 @@ type Config struct {
|
||||
HTTPTimeout time.Duration `json:"httpTimeout"`
|
||||
|
||||
// Custom logger
|
||||
LogOnceIf func(ctx context.Context, err error, id string, errKind ...interface{}) `json:"-"`
|
||||
LogOnceIf func(ctx context.Context, err error, id string, errKind ...any) `json:"-"`
|
||||
}
|
||||
|
||||
// Target implements logger.Target and sends the json
|
||||
@@ -109,7 +109,7 @@ type Target struct {
|
||||
// Channel of log entries.
|
||||
// Reading logCh must hold read lock on logChMu (to avoid read race)
|
||||
// Sending a value on logCh must hold read lock on logChMu (to avoid closing)
|
||||
logCh chan interface{}
|
||||
logCh chan any
|
||||
logChMu sync.RWMutex
|
||||
|
||||
// If this webhook is being re-configured we will
|
||||
@@ -131,7 +131,7 @@ type Target struct {
|
||||
|
||||
// store to persist and replay the logs to the target
|
||||
// to avoid missing events when the target is down.
|
||||
store store.Store[interface{}]
|
||||
store store.Store[any]
|
||||
storeCtxCancel context.CancelFunc
|
||||
|
||||
initQueueOnce once.Init
|
||||
@@ -199,7 +199,7 @@ func (h *Target) initDiskStore(ctx context.Context) (err error) {
|
||||
h.lastStarted = time.Now()
|
||||
go h.startQueueProcessor(ctx, true)
|
||||
|
||||
queueStore := store.NewQueueStore[interface{}](
|
||||
queueStore := store.NewQueueStore[any](
|
||||
filepath.Join(h.config.QueueDir, h.Name()),
|
||||
uint64(h.config.QueueSize),
|
||||
httpLoggerExtension,
|
||||
@@ -289,7 +289,7 @@ func (h *Target) startQueueProcessor(ctx context.Context, mainWorker bool) {
|
||||
h.wg.Add(1)
|
||||
defer h.wg.Done()
|
||||
|
||||
entries := make([]interface{}, 0)
|
||||
entries := make([]any, 0)
|
||||
name := h.Name()
|
||||
|
||||
defer func() {
|
||||
@@ -455,7 +455,7 @@ func (h *Target) startQueueProcessor(ctx context.Context, mainWorker bool) {
|
||||
}
|
||||
}
|
||||
|
||||
entries = make([]interface{}, 0)
|
||||
entries = make([]any, 0)
|
||||
count = 0
|
||||
if !isDirQueue {
|
||||
buf.Reset()
|
||||
@@ -481,7 +481,7 @@ func CreateOrAdjustGlobalBuffer(currentTgt *Target, newTgt *Target) {
|
||||
|
||||
currentBuff, ok := logChBuffers[name]
|
||||
if !ok {
|
||||
logChBuffers[name] = make(chan interface{}, requiredCap)
|
||||
logChBuffers[name] = make(chan any, requiredCap)
|
||||
currentCap = requiredCap
|
||||
} else {
|
||||
currentCap = cap(currentBuff)
|
||||
@@ -489,7 +489,7 @@ func CreateOrAdjustGlobalBuffer(currentTgt *Target, newTgt *Target) {
|
||||
}
|
||||
|
||||
if requiredCap > currentCap {
|
||||
logChBuffers[name] = make(chan interface{}, requiredCap)
|
||||
logChBuffers[name] = make(chan any, requiredCap)
|
||||
|
||||
if len(currentBuff) > 0 {
|
||||
drain:
|
||||
@@ -519,7 +519,7 @@ func New(config Config) (*Target, error) {
|
||||
}
|
||||
|
||||
h := &Target{
|
||||
logCh: make(chan interface{}, config.QueueSize),
|
||||
logCh: make(chan any, config.QueueSize),
|
||||
config: config,
|
||||
batchSize: config.BatchSize,
|
||||
maxWorkers: int64(maxWorkers),
|
||||
@@ -579,7 +579,7 @@ func (h *Target) SendFromStore(key store.Key) (err error) {
|
||||
// Send the log message 'entry' to the http target.
|
||||
// Messages are queued in the disk if the store is enabled
|
||||
// If Cancel has been called the message is ignored.
|
||||
func (h *Target) Send(ctx context.Context, entry interface{}) error {
|
||||
func (h *Target) Send(ctx context.Context, entry any) error {
|
||||
if h.status.Load() == statusClosed {
|
||||
if h.migrateTarget != nil {
|
||||
return h.migrateTarget.Send(ctx, entry)
|
||||
|
||||
@@ -75,7 +75,7 @@ type Config struct {
|
||||
QueueDir string `json:"queueDir"`
|
||||
|
||||
// Custom logger
|
||||
LogOnce func(ctx context.Context, err error, id string, errKind ...interface{}) `json:"-"`
|
||||
LogOnce func(ctx context.Context, err error, id string, errKind ...any) `json:"-"`
|
||||
}
|
||||
|
||||
// Target - Kafka target.
|
||||
@@ -90,12 +90,12 @@ type Target struct {
|
||||
// Channel of log entries.
|
||||
// Reading logCh must hold read lock on logChMu (to avoid read race)
|
||||
// Sending a value on logCh must hold read lock on logChMu (to avoid closing)
|
||||
logCh chan interface{}
|
||||
logCh chan any
|
||||
logChMu sync.RWMutex
|
||||
|
||||
// store to persist and replay the logs to the target
|
||||
// to avoid missing events when the target is down.
|
||||
store store.Store[interface{}]
|
||||
store store.Store[any]
|
||||
storeCtxCancel context.CancelFunc
|
||||
|
||||
initKafkaOnce once.Init
|
||||
@@ -170,7 +170,7 @@ func (h *Target) Init(ctx context.Context) error {
|
||||
|
||||
func (h *Target) initQueueStore(ctx context.Context) (err error) {
|
||||
queueDir := filepath.Join(h.kconfig.QueueDir, h.Name())
|
||||
queueStore := store.NewQueueStore[interface{}](queueDir, uint64(h.kconfig.QueueSize), kafkaLoggerExtension)
|
||||
queueStore := store.NewQueueStore[any](queueDir, uint64(h.kconfig.QueueSize), kafkaLoggerExtension)
|
||||
if err = queueStore.Open(); err != nil {
|
||||
return fmt.Errorf("unable to initialize the queue store of %s webhook: %w", h.Name(), err)
|
||||
}
|
||||
@@ -202,7 +202,7 @@ func (h *Target) startKafkaLogger() {
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Target) logEntry(entry interface{}) {
|
||||
func (h *Target) logEntry(entry any) {
|
||||
atomic.AddInt64(&h.totalMessages, 1)
|
||||
if err := h.send(entry); err != nil {
|
||||
atomic.AddInt64(&h.failedMessages, 1)
|
||||
@@ -210,7 +210,7 @@ func (h *Target) logEntry(entry interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Target) send(entry interface{}) error {
|
||||
func (h *Target) send(entry any) error {
|
||||
if err := h.initKafkaOnce.Do(h.init); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -311,7 +311,7 @@ func (h *Target) IsOnline(_ context.Context) bool {
|
||||
}
|
||||
|
||||
// Send log message 'e' to kafka target.
|
||||
func (h *Target) Send(ctx context.Context, entry interface{}) error {
|
||||
func (h *Target) Send(ctx context.Context, entry any) error {
|
||||
if h.store != nil {
|
||||
// save the entry to the queue store which will be replayed to the target.
|
||||
_, err := h.store.Put(entry)
|
||||
@@ -391,7 +391,7 @@ func (h *Target) Cancel() {
|
||||
// sends log over http to the specified endpoint
|
||||
func New(config Config) *Target {
|
||||
target := &Target{
|
||||
logCh: make(chan interface{}, config.QueueSize),
|
||||
logCh: make(chan any, config.QueueSize),
|
||||
kconfig: config,
|
||||
status: statusOffline,
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ func (t *testLogger) Cancel() {
|
||||
t.current.Store(nil)
|
||||
}
|
||||
|
||||
func (t *testLogger) Send(ctx context.Context, entry interface{}) error {
|
||||
func (t *testLogger) Send(ctx context.Context, entry any) error {
|
||||
tb := t.current.Load()
|
||||
var logf func(format string, args ...any)
|
||||
if tb != nil {
|
||||
|
||||
@@ -39,7 +39,7 @@ type Target interface {
|
||||
Init(ctx context.Context) error
|
||||
IsOnline(ctx context.Context) bool
|
||||
Cancel()
|
||||
Send(ctx context.Context, entry interface{}) error
|
||||
Send(ctx context.Context, entry any) error
|
||||
Type() types.TargetType
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import (
|
||||
var ansiRE = regexp.MustCompile("(\x1b[^m]*m)")
|
||||
|
||||
// Print ANSI Control escape
|
||||
func ansiEscape(format string, args ...interface{}) {
|
||||
func ansiEscape(format string, args ...any) {
|
||||
Esc := "\x1b"
|
||||
fmt.Printf("%s%s", Esc, fmt.Sprintf(format, args...))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user