-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.go
128 lines (99 loc) · 3.22 KB
/
conf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2024 github.com/lvan100
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package conf
import (
"github.com/lvan100/go-conf/internal/appconf"
"github.com/lvan100/go-conf/internal/conf"
)
var (
ErrNotExist = conf.ErrNotExist
ErrInvalidSyntax = conf.ErrInvalidSyntax
)
type (
Reader = conf.Reader
Splitter = conf.Splitter
Converter = conf.Converter
)
// RegisterReader registers its Reader for some kind of file extension.
func RegisterReader(r Reader, ext ...string) {
conf.RegisterReader(r, ext...)
}
// RegisterSplitter registers a Splitter and named it.
func RegisterSplitter(name string, fn Splitter) {
conf.RegisterSplitter(name, fn)
}
// RegisterConverter registers its converter for non-primitive type such as
// time.Time, time.Duration, or other user-defined value type.
func RegisterConverter(fn Converter) {
conf.RegisterConverter(fn)
}
type (
ValidatorInterface = conf.ValidatorInterface
)
// SetValidator sets the validator.
func SetValidator(i ValidatorInterface) {
conf.SetValidator(i)
}
type GetOption = conf.GetOption
// Def used to set default value for conf.Get().
func Def(v string) GetOption {
return conf.Def(v)
}
type (
BindArg = conf.BindArg
BindParam = conf.BindParam
)
// Key binds properties using a key for conf.Bind().
func Key(key string) BindArg {
return conf.Key(key)
}
// Tag binds properties using a tag for conf.Bind().
func Tag(tag string) BindArg {
return conf.Tag(tag)
}
// Param binds properties using BindParam for conf.Bind().
func Param(param BindParam) BindArg {
return conf.Param(param)
}
type ParsedTag = conf.ParsedTag
func ParseTag(tag string) (ret ParsedTag, err error) {
return conf.ParseTag(tag)
}
// FlattenMap can expand the nested array, slice and map.
func FlattenMap(m map[string]interface{}) map[string]string {
return conf.FlattenMap(m)
}
/******************************** Properties *********************************/
// ReadOnlyProperties is the interface for read-only properties.
type ReadOnlyProperties = conf.ReadOnlyProperties
// Properties is a simple properties implementation.
type Properties = conf.Properties
func NewProperties() *Properties {
return conf.NewProperties()
}
type AtomicProperties = conf.AtomicProperties
func NewAtomicProperties() *AtomicProperties {
return conf.NewAtomicProperties()
}
/******************************* Configuration *******************************/
// Configuration is a layered application configuration manager.
type Configuration = appconf.Configuration
func NewConfiguration() *Configuration {
return appconf.NewConfiguration()
}
// Bootstrapper is a layered bootstrap configuration manager.
type Bootstrapper = appconf.Bootstrapper
func NewBootstrapper() *Bootstrapper {
return appconf.NewBootstrapper()
}