github.com/sandwich-go/boost@v1.3.29/misc/cloud/gen_putoptions_optiongen.go (about) 1 // Code generated by optiongen. DO NOT EDIT. 2 // optiongen: github.com/timestee/optiongen 3 4 package cloud 5 6 // PutOptions should use NewPutOptions to initialize it 7 type PutOptions struct { 8 // annotation@ContentType(comment="上传文件的类型") 9 ContentType string 10 // annotation@ContentDisposition(comment="上传文件的内容描述") 11 ContentDisposition string 12 // annotation@CacheControl(comment="上传文件的缓存控制") 13 CacheControl string 14 } 15 16 // NewPutOptions new PutOptions 17 func NewPutOptions(opts ...PutOption) *PutOptions { 18 cc := newDefaultPutOptions() 19 for _, opt := range opts { 20 opt(cc) 21 } 22 if watchDogPutOptions != nil { 23 watchDogPutOptions(cc) 24 } 25 return cc 26 } 27 28 // ApplyOption apply multiple new option 29 func (cc *PutOptions) ApplyOption(opts ...PutOption) { 30 for _, opt := range opts { 31 opt(cc) 32 } 33 } 34 35 // PutOption option func 36 type PutOption func(cc *PutOptions) 37 38 // WithContentType 上传文件的类型 39 func WithContentType(v string) PutOption { 40 return func(cc *PutOptions) { 41 cc.ContentType = v 42 } 43 } 44 45 // WithContentDisposition 上传文件的内容描述 46 func WithContentDisposition(v string) PutOption { 47 return func(cc *PutOptions) { 48 cc.ContentDisposition = v 49 } 50 } 51 52 // WithCacheControl 上传文件的缓存控制 53 func WithCacheControl(v string) PutOption { 54 return func(cc *PutOptions) { 55 cc.CacheControl = v 56 } 57 } 58 59 // InstallPutOptionsWatchDog the installed func will called when NewPutOptions called 60 func InstallPutOptionsWatchDog(dog func(cc *PutOptions)) { watchDogPutOptions = dog } 61 62 // watchDogPutOptions global watch dog 63 var watchDogPutOptions func(cc *PutOptions) 64 65 // newDefaultPutOptions new default PutOptions 66 func newDefaultPutOptions() *PutOptions { 67 cc := &PutOptions{} 68 69 for _, opt := range [...]PutOption{ 70 WithContentType("application/octet-stream"), 71 WithContentDisposition(""), 72 WithCacheControl(""), 73 } { 74 opt(cc) 75 } 76 77 return cc 78 } 79 80 // all getter func 81 func (cc *PutOptions) GetContentType() string { return cc.ContentType } 82 func (cc *PutOptions) GetContentDisposition() string { return cc.ContentDisposition } 83 func (cc *PutOptions) GetCacheControl() string { return cc.CacheControl } 84 85 // PutOptionsVisitor visitor interface for PutOptions 86 type PutOptionsVisitor interface { 87 GetContentType() string 88 GetContentDisposition() string 89 GetCacheControl() string 90 } 91 92 // PutOptionsInterface visitor + ApplyOption interface for PutOptions 93 type PutOptionsInterface interface { 94 PutOptionsVisitor 95 ApplyOption(...PutOption) 96 }