Documentation
¶
Index ¶
- func DotEnv(values map[string]string) []byte
- func StringifyPath(paths ...any) string
- type Decoder
- type Encoder
- type ErrInvalidDecodeValue
- type ErrUnexpectMapKeyType
- type ErrUnexpectMapKeyValue
- type Group
- func (g *Group) Add(v *Var)
- func (g *Group) Bytes() []byte
- func (g *Group) Del(name string)
- func (g *Group) DotEnv(valuer func(*Var) string) []byte
- func (g *Group) Get(name string) *Var
- func (g *Group) Len() int
- func (g *Group) MapEntries(k string) (entries []string)
- func (g *Group) MaskBytes() []byte
- func (g *Group) Reset()
- func (g *Group) SliceLength(k string) int
- type PathWalker
- type Var
- type VarOptions
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StringifyPath ¶
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
func NewDecoder ¶
func (*Decoder) Decode ¶
Example ¶
grp := envconf.NewGroup("TEST") grp.Add(envconf.NewVar("MapStringString_Key", "Value")) grp.Add(envconf.NewVar("MapStringInt_Key", "100")) grp.Add(envconf.NewVar("MapStringInt64_Key", "101")) grp.Add(envconf.NewVar("MapStringPassword_Key", "password")) grp.Add(envconf.NewVar("Slice_0_A", "2")) grp.Add(envconf.NewVar("Slice_0_B", "string")) grp.Add(envconf.NewVar("Array_0_A", "string")) grp.Add(envconf.NewVar("Array_0_B", "2")) dec := envconf.NewDecoder(grp) enc := envconf.NewEncoder(grp) v := &struct { MapStringString map[string]string MapStringInt map[string]int MapStringInt64 map[string]int64 MapStringPassword map[string]datatypes.Password Slice []struct { A int B string } Array [1]struct { B int A string } }{} if err := dec.Decode(v); err != nil { return } if err := enc.Encode(v); err != nil { return } demoVar := envconf.NewVar("VarName", "") fmt.Println(demoVar.GroupName(grp.Name)) fmt.Println(string(grp.Bytes())) fmt.Println(string(grp.MaskBytes()))
Output: TEST__VarName TEST__Array_0_A=string TEST__Array_0_B=2 TEST__MapStringInt64_Key=101 TEST__MapStringInt_Key=100 TEST__MapStringPassword_Key=password TEST__MapStringString_Key=Value TEST__Slice_0_A=2 TEST__Slice_0_B=string TEST__Array_0_A=string TEST__Array_0_B=2 TEST__MapStringInt64_Key=101 TEST__MapStringInt_Key=100 TEST__MapStringPassword_Key=-------- TEST__MapStringString_Key=Value TEST__Slice_0_A=2 TEST__Slice_0_B=string
type ErrInvalidDecodeValue ¶
type ErrInvalidDecodeValue struct {
// contains filtered or unexported fields
}
func NewCannotSetErr ¶
func NewCannotSetErr(t reflect.Type) *ErrInvalidDecodeValue
func NewInvalidDecodeError ¶
func NewInvalidDecodeError(t reflect.Type, reason string) *ErrInvalidDecodeValue
func NewInvalidValueErr ¶
func NewInvalidValueErr() *ErrInvalidDecodeValue
func (*ErrInvalidDecodeValue) Error ¶
func (e *ErrInvalidDecodeValue) Error() string
func (*ErrInvalidDecodeValue) Is ¶
func (e *ErrInvalidDecodeValue) Is(target error) bool
type ErrUnexpectMapKeyType ¶
type ErrUnexpectMapKeyType struct {
// contains filtered or unexported fields
}
func NewErrMarshalUnexpectMapKeyType ¶
func NewErrMarshalUnexpectMapKeyType(t reflect.Type) *ErrUnexpectMapKeyType
func NewErrUnmarshalUnexpectMapKeyType ¶
func NewErrUnmarshalUnexpectMapKeyType(t reflect.Type) *ErrUnexpectMapKeyType
func (*ErrUnexpectMapKeyType) Error ¶
func (e *ErrUnexpectMapKeyType) Error() string
func (*ErrUnexpectMapKeyType) Is ¶
func (e *ErrUnexpectMapKeyType) Is(target error) bool
type ErrUnexpectMapKeyValue ¶
type ErrUnexpectMapKeyValue string
func (ErrUnexpectMapKeyValue) Error ¶
func (e ErrUnexpectMapKeyValue) Error() string
type Group ¶
func ParseGroupFromEnv ¶ added in v0.0.2
Example ¶
package main import ( "fmt" "os" "github.com/sincospro/conf/envconf" ) func main() { _ = os.Setenv("TEST__Array_0_A", "string") _ = os.Setenv("TEST__Array_0_B", "2") _ = os.Setenv("TEST__MapStringInt64_Key", "101") _ = os.Setenv("TEST__MapStringInt_Key", "100") _ = os.Setenv("TEST__MapStringPassword_Key", "password") _ = os.Setenv("TEST__MapStringString_Key", "Value") _ = os.Setenv("TEST__Slice_0_A", "2") _ = os.Setenv("TEST__Slice_0_B", "string") grp := envconf.ParseGroupFromEnv("TEST") _ = os.Unsetenv("TEST__Array_0_A") _ = os.Unsetenv("TEST__Array_0_B") _ = os.Unsetenv("TEST__MapStringInt64_Key") _ = os.Unsetenv("TEST__MapStringInt_Key") _ = os.Unsetenv("TEST__MapStringPassword_Key") _ = os.Unsetenv("TEST__MapStringString_Key") _ = os.Unsetenv("TEST__Slice_0_A") _ = os.Unsetenv("TEST__Slice_0_B") fmt.Print(string(grp.DotEnv(nil))) }
Output: TEST__Array_0_A=string TEST__Array_0_B=2 TEST__MapStringInt64_Key=101 TEST__MapStringInt_Key=100 TEST__MapStringPassword_Key=password TEST__MapStringString_Key=Value TEST__Slice_0_A=2 TEST__Slice_0_B=string
func (*Group) MapEntries ¶
func (*Group) SliceLength ¶
type PathWalker ¶
type PathWalker struct {
// contains filtered or unexported fields
}
func NewPathWalker ¶
func NewPathWalker() *PathWalker
func (*PathWalker) Enter ¶
func (pw *PathWalker) Enter(i any)
func (*PathWalker) Leave ¶
func (pw *PathWalker) Leave()
func (*PathWalker) Paths ¶
func (pw *PathWalker) Paths() []any
func (*PathWalker) String ¶
func (pw *PathWalker) String() string
type Var ¶
type Var struct { Name string Value string Mask string VarOptions }
func (*Var) ParseOption ¶
type VarOptions ¶ added in v0.0.2
type VarOptions struct {
Optional bool
}
Click to show internal directories.
Click to hide internal directories.