github.com/searKing/golang/go@v1.2.117/os/cachefile_options.go (about) 1 // Code generated by "go-option -type CacheFile"; DO NOT EDIT. 2 // Install go-option by "go get install github.com/searKing/golang/tools/go-option" 3 4 package os 5 6 import "time" 7 8 // A CacheFileOption sets options. 9 type CacheFileOption interface { 10 apply(*CacheFile) 11 } 12 13 // EmptyCacheFileOption does not alter the configuration. It can be embedded 14 // in another structure to build custom options. 15 // 16 // This API is EXPERIMENTAL. 17 type EmptyCacheFileOption struct{} 18 19 func (EmptyCacheFileOption) apply(*CacheFile) {} 20 21 // CacheFileOptionFunc wraps a function that modifies CacheFile into an 22 // implementation of the CacheFileOption interface. 23 type CacheFileOptionFunc func(*CacheFile) 24 25 func (f CacheFileOptionFunc) apply(do *CacheFile) { 26 f(do) 27 } 28 29 // ApplyOptions call apply() for all options one by one 30 func (o *CacheFile) ApplyOptions(options ...CacheFileOption) *CacheFile { 31 for _, opt := range options { 32 if opt == nil { 33 continue 34 } 35 opt.apply(o) 36 } 37 return o 38 } 39 40 // WithCacheFile sets CacheFile. 41 func WithCacheFile(v CacheFile) CacheFileOption { 42 return CacheFileOptionFunc(func(o *CacheFile) { 43 *o = v 44 }) 45 } 46 47 // WithCacheFileBucketRootDir sets BucketRootDir in CacheFile. 48 // cache root dir 49 func WithCacheFileBucketRootDir(v string) CacheFileOption { 50 return CacheFileOptionFunc(func(o *CacheFile) { 51 o.BucketRootDir = v 52 }) 53 } 54 55 // WithCacheFileBucketKeyFunc sets BucketKeyFunc in CacheFile. 56 // generate bucket key from key(file path) 57 // bucket key should not contain any of the magic characters recognized by [filepath.Match] 58 // otherwise, bucket key will be escaped by MD5CacheKey 59 // see: https://github.com/golang/go/issues/13516 60 func WithCacheFileBucketKeyFunc(v func(key string) string) CacheFileOption { 61 return CacheFileOptionFunc(func(o *CacheFile) { 62 o.BucketKeyFunc = v 63 }) 64 } 65 66 // WithCacheFileCacheMetaExt sets CacheMetaExt in CacheFile. 67 // the file name extension used by path. ".cache" if empty 68 func WithCacheFileCacheMetaExt(v string) CacheFileOption { 69 return CacheFileOptionFunc(func(o *CacheFile) { 70 o.CacheMetaExt = v 71 }) 72 } 73 74 // WithCacheFileCacheExpiredAfter sets CacheExpiredAfter in CacheFile. 75 // Cache file expiration time, lazy expire cache files base on cache URL modification time 76 func WithCacheFileCacheExpiredAfter(v time.Duration) CacheFileOption { 77 return CacheFileOptionFunc(func(o *CacheFile) { 78 o.CacheExpiredAfter = v 79 }) 80 }