github.com/cloudreve/Cloudreve/v3@v3.0.0-20240224133659-3edb00a6484c/pkg/filesystem/driver/onedrive/options.go (about) 1 package onedrive 2 3 import "time" 4 5 // Option 发送请求的额外设置 6 type Option interface { 7 apply(*options) 8 } 9 10 type options struct { 11 redirect string 12 code string 13 refreshToken string 14 conflictBehavior string 15 expires time.Time 16 useDriverResource bool 17 } 18 19 type optionFunc func(*options) 20 21 // WithCode 设置接口Code 22 func WithCode(t string) Option { 23 return optionFunc(func(o *options) { 24 o.code = t 25 }) 26 } 27 28 // WithRefreshToken 设置接口RefreshToken 29 func WithRefreshToken(t string) Option { 30 return optionFunc(func(o *options) { 31 o.refreshToken = t 32 }) 33 } 34 35 // WithConflictBehavior 设置文件重名后的处理方式 36 func WithConflictBehavior(t string) Option { 37 return optionFunc(func(o *options) { 38 o.conflictBehavior = t 39 }) 40 } 41 42 // WithConflictBehavior 设置文件重名后的处理方式 43 func WithDriverResource(t bool) Option { 44 return optionFunc(func(o *options) { 45 o.useDriverResource = t 46 }) 47 } 48 49 func (f optionFunc) apply(o *options) { 50 f(o) 51 } 52 53 func newDefaultOption() *options { 54 return &options{ 55 conflictBehavior: "fail", 56 useDriverResource: true, 57 expires: time.Now().UTC().Add(time.Duration(1) * time.Hour), 58 } 59 }