go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/configutil/config_options.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package configutil 9 10 import ( 11 "context" 12 "io" 13 ) 14 15 // ConfigOptions are options built for reading configs. 16 type ConfigOptions struct { 17 Context context.Context 18 Contents []io.Reader 19 FilePaths []string 20 Deserializer func(r io.Reader, ref any) error 21 Env map[string]string 22 } 23 24 // Background yields a context for a config options set. 25 func (co ConfigOptions) Background() context.Context { 26 var background context.Context 27 if co.Context != nil { 28 background = co.Context 29 } else { 30 background = context.Background() 31 } 32 33 background = WithConfigPaths(background, co.FilePaths) 34 background = WithEnvVars(background, co.Env) 35 return background 36 }