Skip to content

Load data from various data sources

License

Notifications You must be signed in to change notification settings

chyroc/go-loader

Repository files navigation

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

About

Load data from various data sources

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •