loader

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2022 License: Apache-2.0 Imports: 4 Imported by: 1

README

go-loader

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

Install

go get github.com/chyroc/go-loader

Go-Loader

Software Architecture

The go-loader software is divided into two parts: data extract layer: Extractor and data transform layer: Transformer.

Use the tag of the structure in go to define what Extractor and Transformer are used by the field, and what their parameters are.

Extractor and Transformer

go-loader has several built-in data Extractor and Transformer.

  • build-in Extractor
    • env
    • file
    • inherit
  • build-in Transformer

Of course, users can also customize:

WithExtractor(extractor1, extractor2)

WithTransformer(transformer1, transformer2)
Tag Grammar Rule

The structure field uses loader as the tag name to accept parameters from the user. such as:

type Conf struct {
	GitHubToken string `loader:"env,GITHUB_TOKEN"`
}
Extractor Grammar

In tag loader, read several strings separated by , in turn, the first of which is the name of the Extractor,

and the subsequent list of strings are the parameters of the Extractor function execution

In the above example, the Extractor is env, and GITHUB_TOKEN is passed as a parameter to the env Extractor for processing

You can define only Extractor without defining Transformer. The loader:"env,GITHUB_TOKEN" listed in the previous example only has Extractor

Transformer Grammar

If you still need to define Transformer, separate it with ;

and then a list of strings separated by , where the first string is the name of Transformer, and the following string list is the parameters of Transformer.

type Conf struct {
	GitHubToken string `loader:"env,JSON_TOKEN;json,.GITHUB"`
}

In this example, env JSON_TOKEN stores the json data of a token, then after the Extractor extract the data,

it also needs to use the json Transformer 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 ...Option) error

Load get data from everywhere

Load add some build-in extractor and transformer

  • extractor: env
  • extractor: file

Types

type Extractor

type Extractor = internal.Extractor

type ExtractorReq added in v0.6.0

type ExtractorReq = internal.ExtractorReq

type KeyVal added in v0.6.0

type KeyVal = internal.KeyVal

type Loader

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

Loader impl this package

func New

func New(options ...Option) (*Loader, error)

New create new Loader instance

Generally, you don’t need to call this function, just use Load directly.

type Option

type Option func(r *Loader) error

Option config how Loader work

func WithExtractor

func WithExtractor(extractors ...Extractor) Option

WithExtractor add extractor to Loader

func WithTransform

func WithTransform(transfers ...Transformer) Option

WithTransform add transform to Loader

type Transformer

type Transformer = internal.Transformer

type TransformerReq added in v0.6.0

type TransformerReq = internal.TransformerReq

Directories

Path Synopsis
_examples
load_env command
adapter
extractor_env module

Jump to

Keyboard shortcuts

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