confer


Install
go get github.com/chyroc/confer
Config
Software Architecture
The confer software is divided into two parts: data loading layer and data conversion.
Use the tag of the structure in go to define what loader and transfer are used by the field, and what their parameters are.
Loader
Confer has several built-in data loading layers.
build-in loader:
Of course, users can also customize loader:
loader1 and loader2 should impl interface: Loader
WithLoader(loader1, loader2)
Transfer
Confer has several built-in data data conversion layer.
build-in transfer:
Of course, users can also customize transfer:
transfer1 and transfer2 should impl interface: Transfer
WithTransfer(transfer1, transfer2)
Conf Grammar
The structure field uses conf as the tag name to accept parameters from the user. such as:
type Conf struct {
GitHubToken string `conf:"env,GITHUB_TOKEN"`
}
Conf Loader Grammar
In tag conf, read several strings separated by , in turn, the first of which is the name of the loader layer,
and the subsequent list of strings are the parameters of the loader function execution
In the above example, the loader is env, and GITHUB_TOKEN is passed as a parameter to the env loader for processing
You can define only loader without defining transfer. The conf:"env,GITHUB_TOKEN" listed in the previous example only has loader
Conf Transfer Grammar
If you still need to define transfer, separate it with ; and loader,
and then a list of strings separated by , where the first string is the name of transfer, and the following string list is the parameters of transfer.
Of course, loader The loaded string data will also be the parameters of transfer
type Conf struct {
GitHubToken string `conf:"env,JSON_TOKEN;json,.GITHUB"`
}
In this example, env JSON_TOKEN stores the json data of a token, then after the loader loads the data,
it also needs to use the json transfer to convert the final data from the GITHUB key
Usage