github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/daemon/logger/loggerutils/cache/validate.go (about) 1 package cache 2 3 import ( 4 "strconv" 5 6 "github.com/demonoid81/moby/daemon/logger" 7 "github.com/demonoid81/moby/daemon/logger/local" 8 "github.com/pkg/errors" 9 ) 10 11 func init() { 12 for k, v := range local.LogOptKeys { 13 builtInCacheLogOpts[cachePrefix+k] = v 14 } 15 logger.AddBuiltinLogOpts(builtInCacheLogOpts) 16 logger.RegisterExternalValidator(validateLogCacheOpts) 17 } 18 19 func validateLogCacheOpts(cfg map[string]string) error { 20 if v := cfg[cacheDisabledKey]; v != "" { 21 _, err := strconv.ParseBool(v) 22 if err != nil { 23 return errors.Errorf("invalid value for option %s: %s", cacheDisabledKey, cfg[cacheDisabledKey]) 24 } 25 } 26 return nil 27 } 28 29 // MergeDefaultLogConfig reads the default log opts and makes sure that any caching related keys that exist there are 30 // added to dst. 31 func MergeDefaultLogConfig(dst, defaults map[string]string) { 32 for k, v := range defaults { 33 if !builtInCacheLogOpts[k] { 34 continue 35 } 36 if _, exists := dst[k]; !exists { 37 dst[k] = v 38 } 39 } 40 }