diff --git a/CHANGELOG.md b/CHANGELOG.md index 8853cccc..d2ecf9ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### 12.59.0 * `[fmtutil/table]` Improved separator rendering +* Code refactoring ### 12.58.0 diff --git a/cache/cache.go b/cache/cache.go index c4ce6ff0..083619a8 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -18,7 +18,7 @@ import ( // Cache is cache instance type Cache struct { expiration time.Duration - data map[string]interface{} + data map[string]any expiry map[string]int64 mu *sync.RWMutex isJanitorWorks bool @@ -30,7 +30,7 @@ type Cache struct { func New(defaultExpiration, cleanupInterval time.Duration) *Cache { s := &Cache{ expiration: defaultExpiration, - data: make(map[string]interface{}), + data: make(map[string]any), expiry: make(map[string]int64), mu: &sync.RWMutex{}, } @@ -110,7 +110,7 @@ func (s *Cache) Expired() int { } // Set adds or updates item in cache -func (s *Cache) Set(key string, data interface{}) { +func (s *Cache) Set(key string, data any) { if s == nil { return } @@ -124,7 +124,7 @@ func (s *Cache) Set(key string, data interface{}) { } // Get returns item from cache or nil -func (s *Cache) Get(key string) interface{} { +func (s *Cache) Get(key string) any { if s == nil { return nil } @@ -156,7 +156,7 @@ func (s *Cache) Get(key string) interface{} { } // GetWithExpiration returns item from cache and expiration date or nil -func (s *Cache) GetWithExpiration(key string) (interface{}, time.Time) { +func (s *Cache) GetWithExpiration(key string) (any, time.Time) { if s == nil { return nil, time.Time{} } @@ -209,7 +209,7 @@ func (s *Cache) Flush() { s.mu.Lock() - s.data = make(map[string]interface{}) + s.data = make(map[string]any) s.expiry = make(map[string]int64) s.mu.Unlock() diff --git a/errutil/errutil.go b/errutil/errutil.go index 23b9dad3..982e8e80 100644 --- a/errutil/errutil.go +++ b/errutil/errutil.go @@ -56,7 +56,7 @@ func Chain(funcs ...func() error) error { // ////////////////////////////////////////////////////////////////////////////////// // // Add adds new error to slice -func (e *Errors) Add(errs ...interface{}) *Errors { +func (e *Errors) Add(errs ...any) *Errors { if errs == nil { return e } diff --git a/events/events.go b/events/events.go index 22ad89bf..59be7563 100644 --- a/events/events.go +++ b/events/events.go @@ -26,7 +26,7 @@ type Dispatcher struct { type Handlers []Handler // Handler is a function that handles an event -type Handler func(payload interface{}) +type Handler func(payload any) // ////////////////////////////////////////////////////////////////////////////////// // @@ -109,7 +109,7 @@ func (d *Dispatcher) HasHandler(typ string, handler Handler) bool { } // Dispatch dispatches event with given type and payload -func (d *Dispatcher) Dispatch(typ string, payload interface{}) error { +func (d *Dispatcher) Dispatch(typ string, payload any) error { err := validateArguments(d, typ, nil, false) if err != nil { @@ -136,7 +136,7 @@ func (d *Dispatcher) Dispatch(typ string, payload interface{}) error { // DispatchAndWait dispatches event with given type and payload and waits // until all handlers will be executed -func (d *Dispatcher) DispatchAndWait(typ string, payload interface{}) error { +func (d *Dispatcher) DispatchAndWait(typ string, payload any) error { err := validateArguments(d, typ, nil, false) if err != nil { @@ -212,7 +212,7 @@ func validateArguments(d *Dispatcher, typ string, handler Handler, isHandlerRequ // execWrapper exec wrapper runs given handler function and sends true to the channel // when function is successfully executed -func execWrapper(ch chan bool, handler Handler, payload interface{}) { +func execWrapper(ch chan bool, handler Handler, payload any) { handler(payload) ch <- true } diff --git a/events/events_test.go b/events/events_test.go index b29781bf..9c41990b 100644 --- a/events/events_test.go +++ b/events/events_test.go @@ -90,14 +90,14 @@ func (s *EventsSuite) TestDispatchAndWait(c *C) { // ////////////////////////////////////////////////////////////////////////////////// // -func basicTestHandler(payload interface{}) { +func basicTestHandler(payload any) { return } -func asyncTestHandler1(payload interface{}) { +func asyncTestHandler1(payload any) { atomic.AddUint32(&counter, payload.(uint32)) } -func asyncTestHandler2(payload interface{}) { +func asyncTestHandler2(payload any) { atomic.AddUint32(&counter, payload.(uint32)+1) } diff --git a/events/examples_test.go b/events/examples_test.go index e2fb6492..15f2a8dd 100644 --- a/events/examples_test.go +++ b/events/examples_test.go @@ -78,6 +78,6 @@ func ExampleDispatcher_DispatchAndWait() { // ////////////////////////////////////////////////////////////////////////////////// // -func testHandler(payload interface{}) { +func testHandler(payload any) { fmt.Printf("Got payload: %v\n", payload) } diff --git a/fmtc/cond_wrapper.go b/fmtc/cond_wrapper.go index 28284a53..398a5f37 100644 --- a/fmtc/cond_wrapper.go +++ b/fmtc/cond_wrapper.go @@ -26,7 +26,7 @@ func If(cond bool) CondWrapper { // Print formats using the default formats for its operands and writes to standard // output. -func (cw CondWrapper) Print(a ...interface{}) (int, error) { +func (cw CondWrapper) Print(a ...any) (int, error) { if cw.match == false { return 0, nil } @@ -37,7 +37,7 @@ func (cw CondWrapper) Print(a ...interface{}) (int, error) { // Println formats using the default formats for its operands and writes to standard // output. Spaces are always added between operands and a newline is appended. It // returns the number of bytes written and any write error encountered. -func (cw CondWrapper) Println(a ...interface{}) (int, error) { +func (cw CondWrapper) Println(a ...any) (int, error) { if cw.match == false { return 0, nil } @@ -47,7 +47,7 @@ func (cw CondWrapper) Println(a ...interface{}) (int, error) { // Printf formats according to a format specifier and writes to standard output. It // returns the number of bytes written and any write error encountered. -func (cw CondWrapper) Printf(f string, a ...interface{}) (int, error) { +func (cw CondWrapper) Printf(f string, a ...any) (int, error) { if cw.match == false { return 0, nil } @@ -58,7 +58,7 @@ func (cw CondWrapper) Printf(f string, a ...interface{}) (int, error) { // Fprint formats using the default formats for its operands and writes to w. // Spaces are added between operands when neither is a string. It returns the // number of bytes written and any write error encountered. -func (cw CondWrapper) Fprint(w io.Writer, a ...interface{}) (int, error) { +func (cw CondWrapper) Fprint(w io.Writer, a ...any) (int, error) { if cw.match == false { return 0, nil } @@ -69,7 +69,7 @@ func (cw CondWrapper) Fprint(w io.Writer, a ...interface{}) (int, error) { // Fprintln formats using the default formats for its operands and writes to w. // Spaces are always added between operands and a newline is appended. It returns // the number of bytes written and any write error encountered. -func (cw CondWrapper) Fprintln(w io.Writer, a ...interface{}) (int, error) { +func (cw CondWrapper) Fprintln(w io.Writer, a ...any) (int, error) { if cw.match == false { return 0, nil } @@ -79,7 +79,7 @@ func (cw CondWrapper) Fprintln(w io.Writer, a ...interface{}) (int, error) { // Fprintf formats according to a format specifier and writes to w. It returns // the number of bytes written and any write error encountered. -func (cw CondWrapper) Fprintf(w io.Writer, f string, a ...interface{}) (int, error) { +func (cw CondWrapper) Fprintf(w io.Writer, f string, a ...any) (int, error) { if cw.match == false { return 0, nil } @@ -89,7 +89,7 @@ func (cw CondWrapper) Fprintf(w io.Writer, f string, a ...interface{}) (int, err // Sprint formats using the default formats for its operands and returns the // resulting string. Spaces are added between operands when neither is a string. -func (cw CondWrapper) Sprint(a ...interface{}) string { +func (cw CondWrapper) Sprint(a ...any) string { if cw.match == false { return "" } @@ -99,7 +99,7 @@ func (cw CondWrapper) Sprint(a ...interface{}) string { // Sprintf formats according to a format specifier and returns the resulting // string. -func (cw CondWrapper) Sprintf(f string, a ...interface{}) string { +func (cw CondWrapper) Sprintf(f string, a ...any) string { if cw.match == false { return "" } @@ -110,7 +110,7 @@ func (cw CondWrapper) Sprintf(f string, a ...interface{}) string { // Sprintln formats using the default formats for its operands and returns the // resulting string. Spaces are always added between operands and a newline is // appended. -func (cw CondWrapper) Sprintln(a ...interface{}) string { +func (cw CondWrapper) Sprintln(a ...any) string { if cw.match == false { return "" } @@ -119,7 +119,7 @@ func (cw CondWrapper) Sprintln(a ...interface{}) string { } // TPrint removes all content on the current line and prints the new message -func (cw CondWrapper) TPrint(a ...interface{}) (int, error) { +func (cw CondWrapper) TPrint(a ...any) (int, error) { if cw.match == false { return 0, nil } @@ -128,7 +128,7 @@ func (cw CondWrapper) TPrint(a ...interface{}) (int, error) { } // TPrintf removes all content on the current line and prints the new message -func (cw CondWrapper) TPrintf(f string, a ...interface{}) (int, error) { +func (cw CondWrapper) TPrintf(f string, a ...any) (int, error) { if cw.match == false { return 0, nil } @@ -138,7 +138,7 @@ func (cw CondWrapper) TPrintf(f string, a ...interface{}) (int, error) { // TPrintln removes all content on the current line and prints the new message // with a new line symbol at the end -func (cw CondWrapper) TPrintln(a ...interface{}) (int, error) { +func (cw CondWrapper) TPrintln(a ...any) (int, error) { if cw.match == false { return 0, nil } @@ -148,7 +148,7 @@ func (cw CondWrapper) TPrintln(a ...interface{}) (int, error) { // LPrint formats using the default formats for its operands and writes to standard // output limited by the text size -func (cw CondWrapper) LPrint(maxSize int, a ...interface{}) (int, error) { +func (cw CondWrapper) LPrint(maxSize int, a ...any) (int, error) { if cw.match == false { return 0, nil } @@ -158,7 +158,7 @@ func (cw CondWrapper) LPrint(maxSize int, a ...interface{}) (int, error) { // LPrintf formats according to a format specifier and writes to standard output // limited by the text size -func (cw CondWrapper) LPrintf(maxSize int, f string, a ...interface{}) (int, error) { +func (cw CondWrapper) LPrintf(maxSize int, f string, a ...any) (int, error) { if cw.match == false { return 0, nil } @@ -168,7 +168,7 @@ func (cw CondWrapper) LPrintf(maxSize int, f string, a ...interface{}) (int, err // LPrintln formats using the default formats for its operands and writes to standard // output limited by the text size -func (cw CondWrapper) LPrintln(maxSize int, a ...interface{}) (int, error) { +func (cw CondWrapper) LPrintln(maxSize int, a ...any) (int, error) { if cw.match == false { return 0, nil } @@ -178,7 +178,7 @@ func (cw CondWrapper) LPrintln(maxSize int, a ...interface{}) (int, error) { // TLPrint removes all content on the current line and prints the new message // limited by the text size -func (cw CondWrapper) TLPrint(maxSize int, a ...interface{}) (int, error) { +func (cw CondWrapper) TLPrint(maxSize int, a ...any) (int, error) { if cw.match == false { return 0, nil } @@ -188,7 +188,7 @@ func (cw CondWrapper) TLPrint(maxSize int, a ...interface{}) (int, error) { // TLPrintf removes all content on the current line and prints the new message // limited by the text size -func (cw CondWrapper) TLPrintf(maxSize int, f string, a ...interface{}) (int, error) { +func (cw CondWrapper) TLPrintf(maxSize int, f string, a ...any) (int, error) { if cw.match == false { return 0, nil } @@ -198,7 +198,7 @@ func (cw CondWrapper) TLPrintf(maxSize int, f string, a ...interface{}) (int, er // TPrintln removes all content on the current line and prints the new message // limited by the text size with a new line symbol at the end -func (cw CondWrapper) TLPrintln(maxSize int, a ...interface{}) (int, error) { +func (cw CondWrapper) TLPrintln(maxSize int, a ...any) (int, error) { if cw.match == false { return 0, nil } diff --git a/fmtc/fmtc.go b/fmtc/fmtc.go index 06881b49..416c802f 100644 --- a/fmtc/fmtc.go +++ b/fmtc/fmtc.go @@ -164,7 +164,7 @@ func RemoveColor(name string) { // Named colors: // ?name // -func Print(a ...interface{}) (int, error) { +func Print(a ...any) (int, error) { applyColors(&a, -1, DisableColors) return fmt.Print(a...) } @@ -172,21 +172,21 @@ func Print(a ...interface{}) (int, error) { // Println formats using the default formats for its operands and writes to standard // output. Spaces are always added between operands and a newline is appended. It // returns the number of bytes written and any write error encountered. -func Println(a ...interface{}) (int, error) { +func Println(a ...any) (int, error) { applyColors(&a, -1, DisableColors) return fmt.Println(a...) } // Printf formats according to a format specifier and writes to standard output. It // returns the number of bytes written and any write error encountered. -func Printf(f string, a ...interface{}) (int, error) { +func Printf(f string, a ...any) (int, error) { return fmt.Printf(searchColors(f, -1, DisableColors), a...) } // Fprint formats using the default formats for its operands and writes to w. // Spaces are added between operands when neither is a string. It returns the // number of bytes written and any write error encountered. -func Fprint(w io.Writer, a ...interface{}) (int, error) { +func Fprint(w io.Writer, a ...any) (int, error) { applyColors(&a, -1, DisableColors) return fmt.Fprint(w, a...) } @@ -194,101 +194,101 @@ func Fprint(w io.Writer, a ...interface{}) (int, error) { // Fprintln formats using the default formats for its operands and writes to w. // Spaces are always added between operands and a newline is appended. It returns // the number of bytes written and any write error encountered. -func Fprintln(w io.Writer, a ...interface{}) (int, error) { +func Fprintln(w io.Writer, a ...any) (int, error) { applyColors(&a, -1, DisableColors) return fmt.Fprintln(w, a...) } // Fprintf formats according to a format specifier and writes to w. It returns // the number of bytes written and any write error encountered. -func Fprintf(w io.Writer, f string, a ...interface{}) (int, error) { +func Fprintf(w io.Writer, f string, a ...any) (int, error) { return fmt.Fprintf(w, searchColors(f, -1, DisableColors), a...) } // Sprint formats using the default formats for its operands and returns the // resulting string. Spaces are added between operands when neither is a string. -func Sprint(a ...interface{}) string { +func Sprint(a ...any) string { applyColors(&a, -1, DisableColors) return fmt.Sprint(a...) } // Sprintf formats according to a format specifier and returns the resulting // string. -func Sprintf(f string, a ...interface{}) string { +func Sprintf(f string, a ...any) string { return fmt.Sprintf(searchColors(f, -1, DisableColors), a...) } // Sprintln formats using the default formats for its operands and returns the // resulting string. Spaces are always added between operands and a newline is // appended. -func Sprintln(a ...interface{}) string { +func Sprintln(a ...any) string { applyColors(&a, -1, DisableColors) return fmt.Sprintln(a...) } // Errorf formats according to a format specifier and returns the string as a // value that satisfies error. -func Errorf(f string, a ...interface{}) error { +func Errorf(f string, a ...any) error { return errors.New(Sprintf(f, a...)) } // TPrint removes all content on the current line and prints the new message -func TPrint(a ...interface{}) (int, error) { +func TPrint(a ...any) (int, error) { fmt.Print(_CODE_CLEAN_LINE) return Print(a...) } // TPrintf removes all content on the current line and prints the new message -func TPrintf(f string, a ...interface{}) (int, error) { +func TPrintf(f string, a ...any) (int, error) { fmt.Print(_CODE_CLEAN_LINE) return Printf(f, a...) } // TPrintln removes all content on the current line and prints the new message // with a new line symbol at the end -func TPrintln(a ...interface{}) (int, error) { +func TPrintln(a ...any) (int, error) { fmt.Print(_CODE_CLEAN_LINE) return Println(a...) } // LPrint formats using the default formats for its operands and writes to standard // output limited by the text size -func LPrint(maxSize int, a ...interface{}) (int, error) { +func LPrint(maxSize int, a ...any) (int, error) { s := fmt.Sprint(a...) return fmt.Print(searchColors(s, maxSize, DisableColors)) } // LPrintf formats according to a format specifier and writes to standard output // limited by the text size -func LPrintf(maxSize int, f string, a ...interface{}) (int, error) { +func LPrintf(maxSize int, f string, a ...any) (int, error) { s := fmt.Sprintf(f, a...) return fmt.Print(searchColors(s, maxSize, DisableColors)) } // LPrintln formats using the default formats for its operands and writes to standard // output limited by the text size -func LPrintln(maxSize int, a ...interface{}) (int, error) { +func LPrintln(maxSize int, a ...any) (int, error) { applyColors(&a, maxSize, DisableColors) return fmt.Println(a...) } // TLPrint removes all content on the current line and prints the new message // limited by the text size -func TLPrint(maxSize int, a ...interface{}) (int, error) { +func TLPrint(maxSize int, a ...any) (int, error) { fmt.Print(_CODE_CLEAN_LINE) return LPrint(maxSize, a...) } // TLPrintf removes all content on the current line and prints the new message // limited by the text size -func TLPrintf(maxSize int, f string, a ...interface{}) (int, error) { +func TLPrintf(maxSize int, f string, a ...any) (int, error) { fmt.Print(_CODE_CLEAN_LINE) return LPrintf(maxSize, f, a...) } // TPrintln removes all content on the current line and prints the new message // limited by the text size with a new line symbol at the end -func TLPrintln(maxSize int, a ...interface{}) (int, error) { +func TLPrintln(maxSize int, a ...any) (int, error) { fmt.Print(_CODE_CLEAN_LINE) return LPrintln(maxSize, a...) } @@ -534,7 +534,7 @@ func searchColors(text string, limit int, clean bool) string { return output.String() } -func applyColors(a *[]interface{}, limit int, clean bool) { +func applyColors(a *[]any, limit int, clean bool) { for i, x := range *a { if s, ok := x.(string); ok { (*a)[i] = searchColors(s, limit, clean) diff --git a/fmtutil/fmtutil.go b/fmtutil/fmtutil.go index fb486251..31b7ee73 100644 --- a/fmtutil/fmtutil.go +++ b/fmtutil/fmtutil.go @@ -51,7 +51,7 @@ var SizeSeparator = "" // ////////////////////////////////////////////////////////////////////////////////// // // PrettyNum formats number to "pretty" form (e.g 1234567 -> 1,234,567) -func PrettyNum(i interface{}, separator ...string) string { +func PrettyNum(i any, separator ...string) string { var str string sep := OrderSeparator @@ -101,7 +101,7 @@ func PrettyPerc(i float64) string { } // PrettySize formats value to "pretty" size (e.g 1478182 -> 1.34 Mb) -func PrettySize(i interface{}, separator ...string) string { +func PrettySize(i any, separator ...string) string { var f float64 sep := SizeSeparator diff --git a/fmtutil/table/table.go b/fmtutil/table/table.go index 3130357e..dd7abf96 100644 --- a/fmtutil/table/table.go +++ b/fmtutil/table/table.go @@ -113,7 +113,7 @@ func (t *Table) SetAlignments(align ...uint8) *Table { } // Add adds given data to stack -func (t *Table) Add(data ...interface{}) *Table { +func (t *Table) Add(data ...any) *Table { if t == nil { return nil } @@ -128,7 +128,7 @@ func (t *Table) Add(data ...interface{}) *Table { } // Print renders given data -func (t *Table) Print(data ...interface{}) *Table { +func (t *Table) Print(data ...any) *Table { if t == nil { return nil } @@ -307,8 +307,8 @@ func renderSeparator(t *Table) { fmtc.Println("{s}" + t.separator + "{!}") } -// convertSlice convert slice with interface{} to slice with strings -func convertSlice(data []interface{}) []string { +// convertSlice convert slice with any to slice with strings +func convertSlice(data []any) []string { var result []string for _, item := range data { diff --git a/go.mod b/go.mod index 78ab11c5..9d84ba7d 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/essentialkaos/ek/v12 -go 1.17 +go 1.18 require ( github.com/essentialkaos/check v1.3.0 diff --git a/jsonutil/jsonutil.go b/jsonutil/jsonutil.go index 6147f800..d85ab9a2 100644 --- a/jsonutil/jsonutil.go +++ b/jsonutil/jsonutil.go @@ -24,28 +24,28 @@ var GzipLevel = gzip.BestSpeed // ////////////////////////////////////////////////////////////////////////////////// // // Read reads and decode JSON file -func Read(file string, v interface{}) error { +func Read(file string, v any) error { return readFile(file, v, false) } // ReadGz reads and decode gzipped JSON file -func ReadGz(file string, v interface{}) error { +func ReadGz(file string, v any) error { return readFile(file, v, true) } // Write encodes data to JSON and save it to file -func Write(file string, v interface{}, perms ...os.FileMode) error { +func Write(file string, v any, perms ...os.FileMode) error { return writeFile(file, v, perms, false) } // Write encodes data to gzipped JSON and save it to file -func WriteGz(file string, v interface{}, perms ...os.FileMode) error { +func WriteGz(file string, v any, perms ...os.FileMode) error { return writeFile(file, v, perms, true) } // ////////////////////////////////////////////////////////////////////////////////// // -func readFile(file string, v interface{}, compress bool) error { +func readFile(file string, v any, compress bool) error { fd, err := os.Open(file) if err != nil { @@ -57,7 +57,7 @@ func readFile(file string, v interface{}, compress bool) error { return readData(fd, v, compress) } -func readData(rw io.ReadWriter, v interface{}, compress bool) error { +func readData(rw io.ReadWriter, v any, compress bool) error { var err error var dr io.Reader @@ -76,7 +76,7 @@ func readData(rw io.ReadWriter, v interface{}, compress bool) error { return json.NewDecoder(dr).Decode(v) } -func writeFile(file string, v interface{}, perms []os.FileMode, compressed bool) error { +func writeFile(file string, v any, perms []os.FileMode, compressed bool) error { var perm os.FileMode = 0644 if len(perms) != 0 { @@ -94,7 +94,7 @@ func writeFile(file string, v interface{}, perms []os.FileMode, compressed bool) return writeData(fd, v, compressed) } -func writeData(rw io.ReadWriter, v interface{}, compressed bool) error { +func writeData(rw io.ReadWriter, v any, compressed bool) error { var err error var je *json.Encoder var gw *gzip.Writer diff --git a/knf/knf.go b/knf/knf.go index cec360b9..6de205ee 100644 --- a/knf/knf.go +++ b/knf/knf.go @@ -33,11 +33,11 @@ type Config struct { type Validator struct { Property string // Property name Func PropertyValidator // Validation function - Value interface{} // Expected value + Value any // Expected value } // PropertyValidator is default type of property validation function -type PropertyValidator func(config *Config, prop string, value interface{}) error +type PropertyValidator func(config *Config, prop string, value any) error // ////////////////////////////////////////////////////////////////////////////////// // @@ -199,7 +199,7 @@ func GetD(name string, defvals ...time.Duration) time.Duration { } // Is checks if given property contains given value -func Is(name string, value interface{}) bool { +func Is(name string, value any) bool { if global == nil { return false } @@ -501,7 +501,7 @@ func (c *Config) GetD(name string, defvals ...time.Duration) time.Duration { } // Is checks if given property contains given value -func (c *Config) Is(name string, value interface{}) bool { +func (c *Config) Is(name string, value any) bool { if c == nil || c.mx == nil { return false } diff --git a/knf/knf_test.go b/knf/knf_test.go index 8213d50d..c5d458f1 100644 --- a/knf/knf_test.go +++ b/knf/knf_test.go @@ -497,7 +497,7 @@ func (s *KNFSuite) TestSimpleValidator(c *check.C) { c.Assert(global, check.NotNil) c.Assert(err, check.IsNil) - var simpleValidator = func(config *Config, prop string, value interface{}) error { + var simpleValidator = func(config *Config, prop string, value any) error { if prop == "string:test2" { return fmt.Errorf("ERROR") } diff --git a/knf/validators/fs/validators.go b/knf/validators/fs/validators.go index d91a2a34..d4753e3a 100644 --- a/knf/validators/fs/validators.go +++ b/knf/validators/fs/validators.go @@ -44,7 +44,7 @@ var ( // ////////////////////////////////////////////////////////////////////////////////// // -func validatePerms(config *knf.Config, prop string, value interface{}) error { +func validatePerms(config *knf.Config, prop string, value any) error { perms := value.(string) target := config.GetS(prop) @@ -80,7 +80,7 @@ func validatePerms(config *knf.Config, prop string, value interface{}) error { return nil } -func validateOwner(config *knf.Config, prop string, value interface{}) error { +func validateOwner(config *knf.Config, prop string, value any) error { target := config.GetS(prop) owner := value.(string) @@ -107,7 +107,7 @@ func validateOwner(config *knf.Config, prop string, value interface{}) error { return nil } -func validateOwnerGroup(config *knf.Config, prop string, value interface{}) error { +func validateOwnerGroup(config *knf.Config, prop string, value any) error { target := config.GetS(prop) ownerGroup := value.(string) @@ -134,7 +134,7 @@ func validateOwnerGroup(config *knf.Config, prop string, value interface{}) erro return nil } -func validateFileMode(config *knf.Config, prop string, value interface{}) error { +func validateFileMode(config *knf.Config, prop string, value any) error { perms := value.(os.FileMode) target := config.GetS(prop) @@ -156,7 +156,7 @@ func validateFileMode(config *knf.Config, prop string, value interface{}) error return nil } -func validateMatchPattern(config *knf.Config, prop string, value interface{}) error { +func validateMatchPattern(config *knf.Config, prop string, value any) error { pattern := value.(string) confPath := config.GetS(prop) diff --git a/knf/validators/network/validators.go b/knf/validators/network/validators.go index 0f6d4972..80713ba5 100644 --- a/knf/validators/network/validators.go +++ b/knf/validators/network/validators.go @@ -37,7 +37,7 @@ var ( // ////////////////////////////////////////////////////////////////////////////////// // -func validateIP(config *knf.Config, prop string, value interface{}) error { +func validateIP(config *knf.Config, prop string, value any) error { ipStr := config.GetS(prop) if ipStr == "" { @@ -53,7 +53,7 @@ func validateIP(config *knf.Config, prop string, value interface{}) error { return nil } -func validatePort(config *knf.Config, prop string, value interface{}) error { +func validatePort(config *knf.Config, prop string, value any) error { portStr := config.GetS(prop) if portStr == "" { @@ -69,7 +69,7 @@ func validatePort(config *knf.Config, prop string, value interface{}) error { return nil } -func validateMAC(config *knf.Config, prop string, value interface{}) error { +func validateMAC(config *knf.Config, prop string, value any) error { macStr := config.GetS(prop) if macStr == "" { @@ -85,7 +85,7 @@ func validateMAC(config *knf.Config, prop string, value interface{}) error { return err } -func validateCIDR(config *knf.Config, prop string, value interface{}) error { +func validateCIDR(config *knf.Config, prop string, value any) error { cidrStr := config.GetS(prop) if cidrStr == "" { @@ -101,7 +101,7 @@ func validateCIDR(config *knf.Config, prop string, value interface{}) error { return err } -func validateURL(config *knf.Config, prop string, value interface{}) error { +func validateURL(config *knf.Config, prop string, value any) error { urlStr := config.GetS(prop) if urlStr == "" { diff --git a/knf/validators/regexp/validators.go b/knf/validators/regexp/validators.go index ce78b7da..28785888 100644 --- a/knf/validators/regexp/validators.go +++ b/knf/validators/regexp/validators.go @@ -24,7 +24,7 @@ var ( // ////////////////////////////////////////////////////////////////////////////////// // -func validateRegexp(config *knf.Config, prop string, value interface{}) error { +func validateRegexp(config *knf.Config, prop string, value any) error { pattern := value.(string) confVal := config.GetS(prop) diff --git a/knf/validators/system/validators.go b/knf/validators/system/validators.go index 06308372..b7e3963c 100644 --- a/knf/validators/system/validators.go +++ b/knf/validators/system/validators.go @@ -30,7 +30,7 @@ var ( // ////////////////////////////////////////////////////////////////////////////////// // -func validateUser(config *knf.Config, prop string, value interface{}) error { +func validateUser(config *knf.Config, prop string, value any) error { userNameOrID := config.GetS(prop) if userNameOrID == "" { @@ -44,7 +44,7 @@ func validateUser(config *knf.Config, prop string, value interface{}) error { return nil } -func validateGroup(config *knf.Config, prop string, value interface{}) error { +func validateGroup(config *knf.Config, prop string, value any) error { groupNameOrID := config.GetS(prop) if groupNameOrID == "" { diff --git a/knf/validators/system/validators_linux.go b/knf/validators/system/validators_linux.go index be9f07ab..dc44b9c2 100644 --- a/knf/validators/system/validators_linux.go +++ b/knf/validators/system/validators_linux.go @@ -26,7 +26,7 @@ var ( // ////////////////////////////////////////////////////////////////////////////////// // -func validateInterface(config *knf.Config, prop string, value interface{}) error { +func validateInterface(config *knf.Config, prop string, value any) error { interfaceName := config.GetS(prop) if interfaceName == "" { diff --git a/knf/validators/validators.go b/knf/validators/validators.go index baaf3082..afbf85f9 100644 --- a/knf/validators/validators.go +++ b/knf/validators/validators.go @@ -56,7 +56,7 @@ var ( // ////////////////////////////////////////////////////////////////////////////////// // -func validatorEmpty(config *knf.Config, prop string, value interface{}) error { +func validatorEmpty(config *knf.Config, prop string, value any) error { if config.GetS(prop) == "" { return fmt.Errorf("Property %s can't be empty", prop) } @@ -64,7 +64,7 @@ func validatorEmpty(config *knf.Config, prop string, value interface{}) error { return nil } -func validatorTypeBool(config *knf.Config, prop string, value interface{}) error { +func validatorTypeBool(config *knf.Config, prop string, value any) error { propValue := config.GetS(prop) switch strings.ToLower(propValue) { @@ -78,7 +78,7 @@ func validatorTypeBool(config *knf.Config, prop string, value interface{}) error } } -func validatorTypeNum(config *knf.Config, prop string, value interface{}) error { +func validatorTypeNum(config *knf.Config, prop string, value any) error { propValue := config.GetS(prop) if propValue == "" { @@ -97,7 +97,7 @@ func validatorTypeNum(config *knf.Config, prop string, value interface{}) error return nil } -func validatorTypeFloat(config *knf.Config, prop string, value interface{}) error { +func validatorTypeFloat(config *knf.Config, prop string, value any) error { propValue := config.GetS(prop) if propValue == "" { @@ -116,7 +116,7 @@ func validatorTypeFloat(config *knf.Config, prop string, value interface{}) erro return nil } -func validatorNotContains(config *knf.Config, prop string, value interface{}) error { +func validatorNotContains(config *knf.Config, prop string, value any) error { switch u := value.(type) { case []string: currentValue := config.GetS(prop) @@ -133,7 +133,7 @@ func validatorNotContains(config *knf.Config, prop string, value interface{}) er return getWrongValidatorError(prop) } -func validatorLess(config *knf.Config, prop string, value interface{}) error { +func validatorLess(config *knf.Config, prop string, value any) error { switch value.(type) { case int, int32, int64, uint, uint32, uint64: if config.GetI(prop) < value.(int) { @@ -150,7 +150,7 @@ func validatorLess(config *knf.Config, prop string, value interface{}) error { return nil } -func validatorGreater(config *knf.Config, prop string, value interface{}) error { +func validatorGreater(config *knf.Config, prop string, value any) error { switch value.(type) { case int, int32, int64, uint, uint32, uint64: if config.GetI(prop) > value.(int) { @@ -169,7 +169,7 @@ func validatorGreater(config *knf.Config, prop string, value interface{}) error return nil } -func validatorEquals(config *knf.Config, prop string, value interface{}) error { +func validatorEquals(config *knf.Config, prop string, value any) error { switch u := value.(type) { case int, int32, int64, uint, uint32, uint64: if config.GetI(prop) == value.(int) { @@ -198,7 +198,7 @@ func validatorEquals(config *knf.Config, prop string, value interface{}) error { return nil } -func validatorNotLen(config *knf.Config, prop string, value interface{}) error { +func validatorNotLen(config *knf.Config, prop string, value any) error { if strutil.Len(config.GetS(prop)) != value.(int) { return fmt.Errorf("Property %s must be %d symbols long", prop, value.(int)) } @@ -206,7 +206,7 @@ func validatorNotLen(config *knf.Config, prop string, value interface{}) error { return nil } -func validatorNotPrefix(config *knf.Config, prop string, value interface{}) error { +func validatorNotPrefix(config *knf.Config, prop string, value any) error { if !strings.HasPrefix(config.GetS(prop), value.(string)) { return fmt.Errorf("Property %s must have prefix %q", prop, value.(string)) } @@ -214,7 +214,7 @@ func validatorNotPrefix(config *knf.Config, prop string, value interface{}) erro return nil } -func validatorNotSuffix(config *knf.Config, prop string, value interface{}) error { +func validatorNotSuffix(config *knf.Config, prop string, value any) error { if !strings.HasSuffix(config.GetS(prop), value.(string)) { return fmt.Errorf("Property %s must have suffix %q", prop, value.(string)) } diff --git a/log/log.go b/log/log.go index a28f569d..b5ca62ad 100644 --- a/log/log.go +++ b/log/log.go @@ -36,13 +36,13 @@ const ( // ILogger is interface for compatible loggers type ILogger interface { - Aux(f string, a ...interface{}) error - Debug(f string, a ...interface{}) error - Info(f string, a ...interface{}) error - Warn(f string, a ...interface{}) error - Error(f string, a ...interface{}) error - Crit(f string, a ...interface{}) error - Print(level uint8, f string, a ...interface{}) error + Aux(f string, a ...any) error + Debug(f string, a ...any) error + Info(f string, a ...any) error + Warn(f string, a ...any) error + Error(f string, a ...any) error + Crit(f string, a ...any) error + Print(level uint8, f string, a ...any) error } // ////////////////////////////////////////////////////////////////////////////////// // @@ -156,7 +156,7 @@ func Reopen() error { } // MinLevel defines minimal logging level -func MinLevel(level interface{}) error { +func MinLevel(level any) error { return Global.MinLevel(level) } @@ -176,37 +176,37 @@ func Flush() error { } // Print writes message to global logger output -func Print(level uint8, f string, a ...interface{}) error { +func Print(level uint8, f string, a ...any) error { return Global.Print(level, f, a...) } // Debug writes debug message to global logger output -func Debug(f string, a ...interface{}) error { +func Debug(f string, a ...any) error { return Global.Debug(f, a...) } // Info writes info message to global logger output -func Info(f string, a ...interface{}) error { +func Info(f string, a ...any) error { return Global.Info(f, a...) } // Warn writes warning message to global logger output -func Warn(f string, a ...interface{}) error { +func Warn(f string, a ...any) error { return Global.Warn(f, a...) } // Error writes error message to global logger output -func Error(f string, a ...interface{}) error { +func Error(f string, a ...any) error { return Global.Error(f, a...) } // Crit writes critical message to global logger output -func Crit(f string, a ...interface{}) error { +func Crit(f string, a ...any) error { return Global.Crit(f, a...) } // Aux writes unskippable message (for separators/headers) -func Aux(f string, a ...interface{}) error { +func Aux(f string, a ...any) error { return Global.Aux(f, a...) } @@ -237,7 +237,7 @@ func (l *Logger) Reopen() error { } // MinLevel defines minimal logging level -func (l *Logger) MinLevel(level interface{}) error { +func (l *Logger) MinLevel(level any) error { if l == nil || l.mu == nil { return ErrLoggerIsNil } @@ -314,7 +314,7 @@ func (l *Logger) Set(file string, perms os.FileMode) error { } // Print writes message to logger output -func (l *Logger) Print(level uint8, f string, a ...interface{}) error { +func (l *Logger) Print(level uint8, f string, a ...any) error { if l == nil || l.mu == nil { return ErrLoggerIsNil } @@ -370,7 +370,7 @@ func (l *Logger) Flush() error { } // Debug writes debug message to logger output -func (l *Logger) Debug(f string, a ...interface{}) error { +func (l *Logger) Debug(f string, a ...any) error { if l == nil || l.mu == nil { return ErrLoggerIsNil } @@ -379,7 +379,7 @@ func (l *Logger) Debug(f string, a ...interface{}) error { } // Info writes info message to logger output -func (l *Logger) Info(f string, a ...interface{}) error { +func (l *Logger) Info(f string, a ...any) error { if l == nil || l.mu == nil { return ErrLoggerIsNil } @@ -388,7 +388,7 @@ func (l *Logger) Info(f string, a ...interface{}) error { } // Warn writes warning message to logger output -func (l *Logger) Warn(f string, a ...interface{}) error { +func (l *Logger) Warn(f string, a ...any) error { if l == nil || l.mu == nil { return ErrLoggerIsNil } @@ -397,7 +397,7 @@ func (l *Logger) Warn(f string, a ...interface{}) error { } // Error writes error message to logger output -func (l *Logger) Error(f string, a ...interface{}) error { +func (l *Logger) Error(f string, a ...any) error { if l == nil || l.mu == nil { return ErrLoggerIsNil } @@ -406,7 +406,7 @@ func (l *Logger) Error(f string, a ...interface{}) error { } // Crit writes critical message to logger output -func (l *Logger) Crit(f string, a ...interface{}) error { +func (l *Logger) Crit(f string, a ...any) error { if l == nil || l.mu == nil { return ErrLoggerIsNil } @@ -415,7 +415,7 @@ func (l *Logger) Crit(f string, a ...interface{}) error { } // Aux writes unfiltered message (for separators/headers) to logger output -func (l *Logger) Aux(f string, a ...interface{}) error { +func (l *Logger) Aux(f string, a ...any) error { if l == nil || l.mu == nil { return ErrLoggerIsNil } @@ -471,7 +471,7 @@ func getTime() string { return "[ " + time.Now().Format(TimeFormat) + " ]" } -func convertMinLevelValue(level interface{}) (uint8, error) { +func convertMinLevelValue(level any) (uint8, error) { switch u := level.(type) { case int: diff --git a/log/std.go b/log/std.go index a7c78631..d5b616b2 100644 --- a/log/std.go +++ b/log/std.go @@ -26,21 +26,21 @@ var exitFunc = os.Exit // ////////////////////////////////////////////////////////////////////////////////// // // Fatal is analog of Fatal from stdlib -func (l *StdLogger) Fatal(v ...interface{}) { +func (l *StdLogger) Fatal(v ...any) { l.Logger.Print(CRIT, fmt.Sprint(v...)) l.Logger.Flush() exitFunc(1) } // Fatalf is analog of Fatalf from stdlib -func (l *StdLogger) Fatalf(format string, v ...interface{}) { +func (l *StdLogger) Fatalf(format string, v ...any) { l.Logger.Print(CRIT, fmt.Sprintf(format, v...)) l.Logger.Flush() exitFunc(1) } // Fatalln is analog of Fatalln from stdlib -func (l *StdLogger) Fatalln(v ...interface{}) { +func (l *StdLogger) Fatalln(v ...any) { l.Logger.Print(CRIT, fmt.Sprintln(v...)) l.Logger.Flush() exitFunc(1) @@ -52,7 +52,7 @@ func (l *StdLogger) Output(calldepth int, s string) error { } // Panic is analog of Panic from stdlib -func (l *StdLogger) Panic(v ...interface{}) { +func (l *StdLogger) Panic(v ...any) { s := fmt.Sprint(v...) l.Logger.Print(CRIT, s) l.Logger.Flush() @@ -60,7 +60,7 @@ func (l *StdLogger) Panic(v ...interface{}) { } // Panicf is analog of Panicf from stdlib -func (l *StdLogger) Panicf(format string, v ...interface{}) { +func (l *StdLogger) Panicf(format string, v ...any) { s := fmt.Sprintf(format, v...) l.Logger.Print(CRIT, s) l.Logger.Flush() @@ -68,7 +68,7 @@ func (l *StdLogger) Panicf(format string, v ...interface{}) { } // Panicln is analog of Panicln from stdlib -func (l *StdLogger) Panicln(v ...interface{}) { +func (l *StdLogger) Panicln(v ...any) { s := fmt.Sprintln(v...) l.Logger.Print(CRIT, s) l.Logger.Flush() @@ -76,16 +76,16 @@ func (l *StdLogger) Panicln(v ...interface{}) { } // Print is analog of Print from stdlib -func (l *StdLogger) Print(v ...interface{}) { +func (l *StdLogger) Print(v ...any) { l.Logger.Print(INFO, fmt.Sprint(v...)) } // Printf is analog of Printf from stdlib -func (l *StdLogger) Printf(format string, v ...interface{}) { +func (l *StdLogger) Printf(format string, v ...any) { l.Logger.Print(INFO, fmt.Sprintf(format, v...)) } // Println is analog of Println from stdlib -func (l *StdLogger) Println(v ...interface{}) { +func (l *StdLogger) Println(v ...any) { l.Logger.Print(INFO, fmt.Sprintln(v...)) } diff --git a/options/arguments.go b/options/arguments.go index de95dd8c..86cf919d 100644 --- a/options/arguments.go +++ b/options/arguments.go @@ -138,7 +138,7 @@ func (a Argument) String() string { } // Is returns true if argument equals to given value -func (a Argument) Is(value interface{}) bool { +func (a Argument) Is(value any) bool { switch t := value.(type) { case string: return a.String() == t diff --git a/options/options.go b/options/options.go index 1bbfe7e3..f6591535 100644 --- a/options/options.go +++ b/options/options.go @@ -56,7 +56,7 @@ type V struct { set bool // non-exported field - Value interface{} // default value + Value any // default value } // Map is map with list of options @@ -293,7 +293,7 @@ func (opts *Options) GetF(name string) float64 { } // Is checks if option with given name has given value -func (opts *Options) Is(name string, value interface{}) bool { +func (opts *Options) Is(name string, value any) bool { if opts == nil { return false } @@ -431,7 +431,7 @@ func Has(name string) bool { } // Is checks if option with given name has given value -func Is(name string, value interface{}) bool { +func Is(name string, value any) bool { if global == nil || !global.initialized { return false } @@ -808,7 +808,7 @@ func betweenFloat(val, min, max float64) float64 { } } -func isSupportedType(v interface{}) bool { +func isSupportedType(v any) bool { switch v.(type) { case nil, string, bool, int, float64: return true @@ -817,7 +817,7 @@ func isSupportedType(v interface{}) bool { return false } -func guessType(v interface{}) int { +func guessType(v any) int { switch v.(type) { case string: return STRING diff --git a/pluralize/pluralize.go b/pluralize/pluralize.go index 5ef47b9a..ebcb620b 100644 --- a/pluralize/pluralize.go +++ b/pluralize/pluralize.go @@ -21,12 +21,12 @@ var DefaultPluralizer = En // ////////////////////////////////////////////////////////////////////////////////// // // P pluralizes a word based on the passed number with custom format -func P(format string, n interface{}, data ...string) string { +func P(format string, n any, data ...string) string { return PS(DefaultPluralizer, format, n, data...) } // PS pluralizes a word based on the passed number with custom pluralizer and format -func PS(p Pluralizer, format string, n interface{}, data ...string) string { +func PS(p Pluralizer, format string, n any, data ...string) string { nk, ok := convertNumber(n) if !ok { @@ -60,7 +60,7 @@ func safeSliceGet(data []string, index int) string { return data[index] } -func convertNumber(n interface{}) (int, bool) { +func convertNumber(n any) (int, bool) { switch u := n.(type) { case int32: return int(u), true diff --git a/req/req.go b/req/req.go index 8f8bde84..857bd1cd 100644 --- a/req/req.go +++ b/req/req.go @@ -182,26 +182,26 @@ const USER_AGENT = "go-ek-req" // ////////////////////////////////////////////////////////////////////////////////// // -// Query is a map[string]interface{} used for query -type Query map[string]interface{} +// Query is a map[string]any used for query +type Query map[string]any // Headers is a map[string]string used for headers type Headers map[string]string // Request is basic struct type Request struct { - Method string // Request method - URL string // Request URL - Query Query // Map with query params - Body interface{} // Request body - Headers Headers // Map with headers - ContentType string // Content type header - Accept string // Accept header - BasicAuthUsername string // Basic auth username - BasicAuthPassword string // Basic auth password - AutoDiscard bool // Automatically discard all responses with status code != 200 - FollowRedirect bool // Follow redirect - Close bool // Close indicates whether to close the connection after sending request + Method string // Request method + URL string // Request URL + Query Query // Map with query params + Body any // Request body + Headers Headers // Map with headers + ContentType string // Content type header + Accept string // Accept header + BasicAuthUsername string // Basic auth username + BasicAuthPassword string // Basic auth password + AutoDiscard bool // Automatically discard all responses with status code != 200 + FollowRedirect bool // Follow redirect + Close bool // Close indicates whether to close the connection after sending request } // Response is struct contains response data and properties @@ -456,7 +456,7 @@ func (r *Response) Discard() { } // JSON decodes json encoded body -func (r *Response) JSON(v interface{}) error { +func (r *Response) JSON(v any) error { defer r.Body.Close() return json.NewDecoder(r.Body).Decode(v) } @@ -697,7 +697,7 @@ func createFormFile(w *multipart.Writer, fieldName, file string) (io.Writer, err return w.CreateFormFile(fieldName, filepath.Base(file)) } -func getBodyReader(body interface{}) (io.Reader, error) { +func getBodyReader(body any) (io.Reader, error) { switch u := body.(type) { case nil: return nil, nil diff --git a/secstr/secure_string.go b/secstr/secure_string.go index 208baf7b..6e131e81 100644 --- a/secstr/secure_string.go +++ b/secstr/secure_string.go @@ -28,7 +28,7 @@ type String struct { // ////////////////////////////////////////////////////////////////////////////////// // // NewSecureString creates new secure string -func NewSecureString(data interface{}) (*String, error) { +func NewSecureString(data any) (*String, error) { switch v := data.(type) { case []byte: return secureStringFromSlice(v) diff --git a/secstr/secure_string_windows.go b/secstr/secure_string_windows.go index 0f75a865..012af0a0 100644 --- a/secstr/secure_string_windows.go +++ b/secstr/secure_string_windows.go @@ -16,7 +16,7 @@ type String struct { // ////////////////////////////////////////////////////////////////////////////////// // // ❗ NewSecureString creates new secure string -func NewSecureString(data interface{}) (*String, error) { +func NewSecureString(data any) (*String, error) { panic("UNSUPPORTED") return nil, nil } diff --git a/sliceutil/sliceutil.go b/sliceutil/sliceutil.go index 49f9d351..0ed67c25 100644 --- a/sliceutil/sliceutil.go +++ b/sliceutil/sliceutil.go @@ -50,13 +50,13 @@ func CopyFloats(slice []float64) []float64 { return s } -// StringToInterface converts slice with strings to slice with interface{} -func StringToInterface(data []string) []interface{} { +// StringToInterface converts slice with strings to slice with any +func StringToInterface(data []string) []any { if len(data) == 0 { return nil } - result := make([]interface{}, len(data)) + result := make([]any, len(data)) for i, r := range data { result[i] = r @@ -65,13 +65,13 @@ func StringToInterface(data []string) []interface{} { return result } -// IntToInterface converts slice with ints to slice with interface{} -func IntToInterface(data []int) []interface{} { +// IntToInterface converts slice with ints to slice with any +func IntToInterface(data []int) []any { if len(data) == 0 { return nil } - result := make([]interface{}, len(data)) + result := make([]any, len(data)) for i, r := range data { result[i] = r diff --git a/sliceutil/sliceutil_test.go b/sliceutil/sliceutil_test.go index 0e400981..14c0a59c 100644 --- a/sliceutil/sliceutil_test.go +++ b/sliceutil/sliceutil_test.go @@ -41,14 +41,14 @@ func (s *SliceSuite) TestStringToInterface(c *C) { source := []string{"1", "2", "3"} c.Assert(StringToInterface(nil), IsNil) - c.Assert(StringToInterface(source), DeepEquals, []interface{}{"1", "2", "3"}) + c.Assert(StringToInterface(source), DeepEquals, []any{"1", "2", "3"}) } func (s *SliceSuite) TestIntToInterface(c *C) { source := []int{1, 2, 3} c.Assert(IntToInterface(nil), IsNil) - c.Assert(IntToInterface(source), DeepEquals, []interface{}{1, 2, 3}) + c.Assert(IntToInterface(source), DeepEquals, []any{1, 2, 3}) } func (s *SliceSuite) TestStringToError(c *C) { diff --git a/spinner/spinner.go b/spinner/spinner.go index 058f397f..1505c6ee 100644 --- a/spinner/spinner.go +++ b/spinner/spinner.go @@ -72,7 +72,7 @@ var mu = &sync.RWMutex{} // ////////////////////////////////////////////////////////////////////////////////// // // Show shows spinner with given task description -func Show(message string, args ...interface{}) { +func Show(message string, args ...any) { mu.RLock() if !isHidden { mu.RUnlock() @@ -94,7 +94,7 @@ func Show(message string, args ...interface{}) { } // Update updates task description -func Update(message string, args ...interface{}) { +func Update(message string, args ...any) { mu.RLock() if isHidden { mu.RUnlock() diff --git a/terminal/terminal.go b/terminal/terminal.go index 8e7b40c6..3491d5c8 100644 --- a/terminal/terminal.go +++ b/terminal/terminal.go @@ -114,7 +114,7 @@ func ReadPasswordSecure(title string, nonEmpty bool) (*secstr.String, error) { } // PrintErrorMessage prints error message -func PrintErrorMessage(message string, args ...interface{}) { +func PrintErrorMessage(message string, args ...any) { if len(args) == 0 { fmtc.Fprintf(os.Stderr, ErrorColorTag+"%s{!}\n", message) } else { @@ -123,7 +123,7 @@ func PrintErrorMessage(message string, args ...interface{}) { } // PrintWarnMessage prints warning message -func PrintWarnMessage(message string, args ...interface{}) { +func PrintWarnMessage(message string, args ...any) { if len(args) == 0 { fmtc.Fprintf(os.Stderr, WarnColorTag+"%s{!}\n", message) } else { diff --git a/terminal/terminal_windows.go b/terminal/terminal_windows.go index b40046fb..f208761c 100644 --- a/terminal/terminal_windows.go +++ b/terminal/terminal_windows.go @@ -59,12 +59,12 @@ func ReadPasswordSecure(title string, nonEmpty bool) (*secstr.String, error) { } // ❗ PrintErrorMessage prints error message -func PrintErrorMessage(message string, args ...interface{}) { +func PrintErrorMessage(message string, args ...any) { panic("UNSUPPORTED") } // ❗ PrintWarnMessage prints warning message -func PrintWarnMessage(message string, args ...interface{}) { +func PrintWarnMessage(message string, args ...any) { panic("UNSUPPORTED") } diff --git a/timeutil/timeutil.go b/timeutil/timeutil.go index bea94790..01ba45ba 100644 --- a/timeutil/timeutil.go +++ b/timeutil/timeutil.go @@ -33,7 +33,7 @@ const ( // ////////////////////////////////////////////////////////////////////////////////// // // PrettyDuration returns pretty duration (e.g. 1 hour 45 seconds) -func PrettyDuration(d interface{}) string { +func PrettyDuration(d any) string { dur, ok := convertDuration(d) if !ok { @@ -48,7 +48,7 @@ func PrettyDuration(d interface{}) string { } // PrettyDurationInDays returns pretty duration in days (e.g. 15 days) -func PrettyDurationInDays(d interface{}) string { +func PrettyDurationInDays(d any) string { dur, ok := convertDuration(d) if !ok { @@ -65,7 +65,7 @@ func PrettyDurationInDays(d interface{}) string { } // ShortDuration returns pretty short duration (e.g. 1:37) -func ShortDuration(d interface{}, highPrecision ...bool) string { +func ShortDuration(d any, highPrecision ...bool) string { dur, ok := convertDuration(d) if !ok { @@ -367,7 +367,7 @@ func NextWeekend(t time.Time) time.Time { // It's ok to have so long method here // codebeat:disable[LOC,ABC] -func convertDuration(d interface{}) (time.Duration, bool) { +func convertDuration(d any) (time.Duration, bool) { switch u := d.(type) { case time.Duration: return u, true