@@ -39,18 +39,18 @@ type option struct {
3939 opt Opt
4040}
4141
42- func (o * option ) GetValue () interface {} {
42+ func (o * option ) GetValue () any {
4343 return o .value .Load ()
4444}
4545
46- func (o * option ) Get () (value interface {} ) {
46+ func (o * option ) Get () (value any ) {
4747 if value = o .value .Load (); value == nil {
4848 value = o .opt .Default
4949 }
5050 return
5151}
5252
53- func (o * option ) Set (c * Config , newvalue interface {} ) {
53+ func (o * option ) Set (c * Config , newvalue any ) {
5454 oldvalue := o .value .Swap (newvalue )
5555 if oldvalue == nil {
5656 oldvalue = o .opt .Default
@@ -59,7 +59,7 @@ func (o *option) Set(c *Config, newvalue interface{}) {
5959}
6060
6161// Observer is used to observe the change of the option value.
62- type Observer func (optName string , oldValue , newValue interface {} )
62+ type Observer func (optName string , oldValue , newValue any )
6363
6464// Config is used to manage the configuration options.
6565type Config struct {
@@ -74,7 +74,7 @@ type Config struct {
7474 // Errorf is used to log the error.
7575 //
7676 // Default: log.Printf
77- Errorf func (format string , args ... interface {} )
77+ Errorf func (format string , args ... any )
7878
7979 gen uint64
8080 gsep string
@@ -127,10 +127,10 @@ func (c *Config) SetVersion(version string) {
127127}
128128
129129func (c * Config ) fixOptionName (name string ) string {
130- return strings .Replace (name , "-" , "_" , - 1 )
130+ return strings .ReplaceAll (name , "-" , "_" )
131131}
132132
133- func (c * Config ) errorf (format string , args ... interface {} ) {
133+ func (c * Config ) errorf (format string , args ... any ) {
134134 if c .Errorf == nil {
135135 log .Printf (format , args ... )
136136 } else {
@@ -147,7 +147,7 @@ func (c *Config) Observe(observers ...Observer) {
147147 c .observers = append (c .observers , observers ... )
148148}
149149
150- func (c * Config ) observe (o * option , old , new interface {} ) {
150+ func (c * Config ) observe (o * option , old , new any ) {
151151 if ! reflect .DeepEqual (old , new ) {
152152 atomic .AddUint64 (& c .gen , 1 )
153153 for _ , observe := range c .observers {
@@ -297,8 +297,8 @@ func (c *Config) getOpts(filter func(Opt) bool) []Opt {
297297 return opts
298298}
299299
300- func (c * Config ) updateOpt (name string , value interface {} , set bool ) (
301- * option , interface {} , error ) {
300+ func (c * Config ) updateOpt (name string , value any , set bool ) (
301+ * option , any , error ) {
302302 if value == nil {
303303 return nil , nil , nil
304304 }
@@ -333,20 +333,19 @@ func (c *Config) updateOpt(name string, value interface{}, set bool) (
333333 return opt , newvalue , nil
334334}
335335
336- func (c * Config ) checkMultilayerMap (ms map [string ]interface {} ) (yes bool ) {
336+ func (c * Config ) checkMultilayerMap (ms map [string ]any ) (yes bool ) {
337337 for _ , value := range ms {
338338 switch value .(type ) {
339339 case map [string ]string ,
340- map [string ]interface {} ,
341- map [interface {}] interface {} :
340+ map [string ]any ,
341+ map [any ] any :
342342 return true
343343 }
344344 }
345345 return false
346346}
347347
348- func (c * Config ) flatmap2 (prefix string , results map [string ]interface {},
349- maps map [interface {}]interface {}) {
348+ func (c * Config ) flatmap2 (prefix string , results map [string ]any , maps map [any ]any ) {
350349 if prefix != "" {
351350 prefix += c .gsep
352351 }
@@ -364,17 +363,17 @@ func (c *Config) flatmap2(prefix string, results map[string]interface{},
364363 for _k , _v := range vs {
365364 results [prefix + k + c .gsep + _k ] = _v
366365 }
367- case map [string ]interface {} :
366+ case map [string ]any :
368367 c .flatmap (prefix + k , results , vs )
369- case map [interface {}] interface {} :
368+ case map [any ] any :
370369 c .flatmap2 (prefix + k , results , vs )
371370 default :
372371 results [prefix + k ] = value
373372 }
374373 }
375374}
376375
377- func (c * Config ) flatmap (prefix string , results , maps map [string ]interface {} ) {
376+ func (c * Config ) flatmap (prefix string , results , maps map [string ]any ) {
378377 if prefix != "" {
379378 prefix += c .gsep
380379 }
@@ -385,19 +384,19 @@ func (c *Config) flatmap(prefix string, results, maps map[string]interface{}) {
385384 for k , v := range vs {
386385 results [prefix + key + c .gsep + k ] = v
387386 }
388- case map [string ]interface {} :
387+ case map [string ]any :
389388 c .flatmap (prefix + key , results , vs )
390- case map [interface {}] interface {} :
389+ case map [any ] any :
391390 c .flatmap2 (prefix + key , results , vs )
392391 default :
393392 results [prefix + key ] = value
394393 }
395394 }
396395}
397396
398- func (c * Config ) flatMap (maps map [string ]interface {} ) map [string ]interface {} {
397+ func (c * Config ) flatMap (maps map [string ]any ) map [string ]any {
399398 if c .checkMultilayerMap (maps ) {
400- tmp := make (map [string ]interface {} , len (maps )* 2 )
399+ tmp := make (map [string ]any , len (maps )* 2 )
401400 c .flatmap ("" , tmp , maps )
402401 return tmp
403402 }
@@ -408,7 +407,7 @@ func (c *Config) flatMap(maps map[string]interface{}) map[string]interface{} {
408407// and load all if failing to parse the value of any option.
409408//
410409// If force is missing or false, ignore the assigned options.
411- func (c * Config ) LoadMap (options map [string ]interface {} , force ... bool ) error {
410+ func (c * Config ) LoadMap (options map [string ]any , force ... bool ) error {
412411 if len (options ) == 0 {
413412 return nil
414413 }
@@ -420,7 +419,7 @@ func (c *Config) LoadMap(options map[string]interface{}, force ...bool) error {
420419
421420 type opt struct {
422421 name string
423- value interface {}
422+ value any
424423 option * option
425424 }
426425
@@ -454,14 +453,14 @@ func (c *Config) LoadMap(options map[string]interface{}, force ...bool) error {
454453}
455454
456455// Parse parses the option value named name, and returns it.
457- func (c * Config ) Parse (name string , value interface {} ) (interface {} , error ) {
456+ func (c * Config ) Parse (name string , value any ) (any , error ) {
458457 name = c .fixOptionName (name )
459458 _ , value , err := c .updateOpt (name , value , false )
460459 return value , err
461460}
462461
463462// Set is used to reset the option named name to value.
464- func (c * Config ) Set (name string , value interface {} ) (err error ) {
463+ func (c * Config ) Set (name string , value any ) (err error ) {
465464 name = c .fixOptionName (name )
466465 _ , _ , err = c .updateOpt (name , value , true )
467466 if err == ErrNoOpt && c .ignore {
@@ -473,7 +472,7 @@ func (c *Config) Set(name string, value interface{}) (err error) {
473472// Get returns the value of the option named name.
474473//
475474// Return nil if this option does not exist.
476- func (c * Config ) Get (name string ) (value interface {} ) {
475+ func (c * Config ) Get (name string ) (value any ) {
477476 name = c .fixOptionName (name )
478477 if opt , ok := c .options [name ]; ok {
479478 value = opt .Get ()
@@ -486,7 +485,7 @@ func (c *Config) Get(name string) (value interface{}) {
486485}
487486
488487// Must is the same as Get, but panic if the returned value is nil.
489- func (c * Config ) Must (name string ) (value interface {} ) {
488+ func (c * Config ) Must (name string ) (value any ) {
490489 if value = c .Get (name ); value == nil {
491490 panic (fmt .Errorf ("no option named name '%s'" , name ))
492491 }
0 commit comments