github.com/sandwich-go/boost@v1.3.29/xos/gen_copyoptions_optiongen.go (about) 1 // Code generated by optiongen. DO NOT EDIT. 2 // optiongen: github.com/timestee/optiongen 3 4 package xos 5 6 import "os" 7 8 // CopyOptions should use NewCopyOptions to initialize it 9 type CopyOptions struct { 10 // OnSymlink can specify what to do on symlink 11 OnSymlink func(src string) SymlinkAction 12 // Skip can specify which files should be skipped 13 Skip func(src string) (bool, error) 14 // AddPermission to every entities, 15 AddPermission os.FileMode 16 // Sync file after copy. 17 Sync bool 18 } 19 20 // NewCopyOptions new CopyOptions 21 func NewCopyOptions(opts ...CopyOption) *CopyOptions { 22 cc := newDefaultCopyOptions() 23 for _, opt := range opts { 24 opt(cc) 25 } 26 if watchDogCopyOptions != nil { 27 watchDogCopyOptions(cc) 28 } 29 return cc 30 } 31 32 // ApplyOption apply multiple new option 33 func (cc *CopyOptions) ApplyOption(opts ...CopyOption) { 34 for _, opt := range opts { 35 opt(cc) 36 } 37 } 38 39 // CopyOption option func 40 type CopyOption func(cc *CopyOptions) 41 42 // WithCopyOnSymlink option func for filed OnSymlink 43 func WithCopyOnSymlink(v func(src string) SymlinkAction) CopyOption { 44 return func(cc *CopyOptions) { 45 cc.OnSymlink = v 46 } 47 } 48 49 // WithCopySkip option func for filed Skip 50 func WithCopySkip(v func(src string) (bool, error)) CopyOption { 51 return func(cc *CopyOptions) { 52 cc.Skip = v 53 } 54 } 55 56 // WithCopyAddPermission option func for filed AddPermission 57 func WithCopyAddPermission(v os.FileMode) CopyOption { 58 return func(cc *CopyOptions) { 59 cc.AddPermission = v 60 } 61 } 62 63 // WithCopySync option func for filed Sync 64 func WithCopySync(v bool) CopyOption { 65 return func(cc *CopyOptions) { 66 cc.Sync = v 67 } 68 } 69 70 // InstallCopyOptionsWatchDog the installed func will called when NewCopyOptions called 71 func InstallCopyOptionsWatchDog(dog func(cc *CopyOptions)) { watchDogCopyOptions = dog } 72 73 // watchDogCopyOptions global watch dog 74 var watchDogCopyOptions func(cc *CopyOptions) 75 76 // newDefaultCopyOptions new default CopyOptions 77 func newDefaultCopyOptions() *CopyOptions { 78 cc := &CopyOptions{} 79 80 for _, opt := range [...]CopyOption{ 81 WithCopyOnSymlink(func(src string) SymlinkAction { 82 return Shallow 83 }), 84 WithCopySkip(func(src string) (bool, error) { 85 return false, nil 86 }), 87 WithCopyAddPermission(0), 88 WithCopySync(false), 89 } { 90 opt(cc) 91 } 92 93 return cc 94 } 95 96 // all getter func 97 func (cc *CopyOptions) GetOnSymlink() func(src string) SymlinkAction { return cc.OnSymlink } 98 func (cc *CopyOptions) GetSkip() func(src string) (bool, error) { return cc.Skip } 99 func (cc *CopyOptions) GetAddPermission() os.FileMode { return cc.AddPermission } 100 func (cc *CopyOptions) GetSync() bool { return cc.Sync } 101 102 // CopyOptionsVisitor visitor interface for CopyOptions 103 type CopyOptionsVisitor interface { 104 GetOnSymlink() func(src string) SymlinkAction 105 GetSkip() func(src string) (bool, error) 106 GetAddPermission() os.FileMode 107 GetSync() bool 108 } 109 110 // CopyOptionsInterface visitor + ApplyOption interface for CopyOptions 111 type CopyOptionsInterface interface { 112 CopyOptionsVisitor 113 ApplyOption(...CopyOption) 114 }