github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/config/config.go (about) 1 // Licensed under the Apache License, Version 2.0 (the "License"); 2 // you may not use this file except in compliance with the License. 3 // You may obtain a copy of the License at 4 // 5 // https://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an "AS IS" BASIS, 9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 // See the License for the specific language governing permissions and 11 // limitations under the License. 12 // 13 // Original source: github.com/micro/go-micro/v3/config/config.go 14 15 // Package config is an interface for dynamic configuration. 16 package config 17 18 import ( 19 "time" 20 ) 21 22 // DefaultConfig implementation 23 var DefaultConfig Config 24 25 // Config is an interface abstraction for dynamic configuration 26 type Config interface { 27 Get(path string, options ...Option) (Value, error) 28 Set(path string, val interface{}, options ...Option) error 29 Delete(path string, options ...Option) error 30 } 31 32 // Value represents a value of any type 33 type Value interface { 34 Exists() bool 35 Bool(def bool) bool 36 Int(def int) int 37 String(def string) string 38 Float64(def float64) float64 39 Duration(def time.Duration) time.Duration 40 StringSlice(def []string) []string 41 StringMap(def map[string]string) map[string]string 42 Scan(val interface{}) error 43 Bytes() []byte 44 } 45 46 type Options struct { 47 Secret bool 48 } 49 50 type Option func(o *Options) 51 52 func Secret(b bool) Option { 53 return func(o *Options) { 54 o.Secret = b 55 } 56 } 57 58 type Secrets interface { 59 Config 60 } 61 62 // Get a value at the path 63 func Get(path string, options ...Option) (Value, error) { 64 return DefaultConfig.Get(path, options...) 65 } 66 67 // Set the value at a path 68 func Set(path string, val interface{}, options ...Option) error { 69 return DefaultConfig.Set(path, val, options...) 70 } 71 72 // Delete the value at a path 73 func Delete(path string, options ...Option) error { 74 return DefaultConfig.Delete(path, options...) 75 }