conf
API
conf
packageAPI reference for the conf
package.
Imports
(7)
S
struct
Builder
Builder is a builder for configuration loading.
pkg/v1/conf/conf.go:24-30
type Builder struct
Fields
| Name | Type | Description |
|---|---|---|
| domain | string | |
| confType | string | |
| prefix | string | |
| cascading | bool | |
| optional | bool |
F
function
NewBuilder
NewBuilder creates a new configuration builder for the given domain.
Parameters
domain
string
Returns
*Builder[T]
pkg/v1/conf/conf.go:33-38
func NewBuilder[T any](domain string) *Builder[T]
{
return &Builder[T]{
domain: domain,
cascading: true,
}
}
F
function
loadFile
Parameters
path
string
v
any
Returns
error
pkg/v1/conf/conf.go:132-139
func loadFile(path string, v any) error
{
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
return json.NewDecoder(f).Decode(v)
}
F
function
InitConfig
InitConfig is a compatibility wrapper using the new Builder.
Parameters
opts
Returns
*T
error
pkg/v1/conf/conf.go:143-148
func InitConfig[T any](opts types.ConfigOptions) (*T, error)
{
return NewBuilder[T](opts.Domain).
WithType(opts.Type).
WithPrefix(opts.Prefix).
Build()
}