github.com/hedzr/evendeep@v0.4.8/def_lazyinit.go (about)

     1  package evendeep
     2  
     3  import (
     4  	"reflect"
     5  	"sync"
     6  )
     7  
     8  var onceLazyInitRoutines sync.Once         //nolint:gochecknoglobals //i know that
     9  var copyToRoutines map[reflect.Kind]copyfn //nolint:gochecknoglobals //i know that
    10  var otherLazyRoutines []func()             //nolint:gochecknoglobals //i know that
    11  
    12  type copyfn func(c *cpController, params *Params, from, to reflect.Value) (err error)
    13  
    14  func lazyInitRoutines() {
    15  	onceLazyInitRoutines.Do(func() {
    16  		copyToRoutines = map[reflect.Kind]copyfn{ //nolint:exhaustive //also kind har human-right
    17  			reflect.Ptr:           copyPointer,
    18  			reflect.Uintptr:       copyUintptr,
    19  			reflect.UnsafePointer: copyUnsafePointer,
    20  			reflect.Chan:          copyChan,
    21  			reflect.Interface:     copyInterface,
    22  			reflect.Struct:        copyStruct,
    23  			reflect.Slice:         copySlice,
    24  			reflect.Array:         copyArray,
    25  			reflect.Map:           copyMap,
    26  			// reflect.Func:          copyFunc,
    27  
    28  			// Invalid Kind = iota
    29  
    30  			// Bool
    31  			// Int
    32  			// Int8
    33  			// Int16
    34  			// Int32
    35  			// Int64
    36  			// Uint
    37  			// Uint8
    38  			// Uint16
    39  			// Uint32
    40  			// Uint64
    41  			// Uintptr
    42  			// Float32
    43  			// Float64
    44  			// Complex64
    45  			// Complex128
    46  
    47  			// Array
    48  			// Chan
    49  			// Func
    50  			// Interface
    51  			// Map
    52  			// Ptr
    53  			// Slice
    54  			// Struct
    55  
    56  			// String
    57  
    58  			// UnsafePointer
    59  		}
    60  
    61  		for _, fn := range otherLazyRoutines {
    62  			if fn != nil {
    63  				fn()
    64  			}
    65  		}
    66  	})
    67  }
    68  
    69  func registerInitRoutines(fn func())     { otherRoutines = append(otherRoutines, fn) }         //nolint:lll,unused,deadcode //usable
    70  func registerLazyInitRoutines(fn func()) { otherLazyRoutines = append(otherLazyRoutines, fn) } //nolint:lll,unused,deadcode //usable