confer

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

README

confer

codecov go report card test status Apache-2.0 license Go.Dev reference Go project version

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:

  • env

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:

  • TODO

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(source interface{}, options ...ImplOption) error

Load get data, and assign to source

source must a pointer to struct

Types

type Impl

type Impl struct {
	// contains filtered or unexported fields
}

type ImplOption

type ImplOption func(r *Impl) error

func WithLoader

func WithLoader(loaders ...Loader) ImplOption

func WithTransfer

func WithTransfer(transfers ...Transfer) ImplOption

type Loader

type Loader interface {
	Name() string
	Load(args []string) (string, error)
}

type Transfer

type Transfer interface {
	Name() string
	Transfer(data string, args []string, typ reflect.Type) (interface{}, error)
}

Directories

Path Synopsis
_examples
load_env command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL