gostructor

package module
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2020 License: MIT Imports: 4 Imported by: 2

README

Gostructor Actions Status Go Report Card codecov


Version: 0.4.1

Universal configuration library by tags

Current supporting input formats

  • hocon values
  • default values
  • environment variables

Current supporting types

  • int, int8, int16, int32, int64
  • float32, float64
  • string
  • bool
  • map[string\int]string\int\float32\float64
  • slices of any types from (int32, int64, int, string, bool, float32, float64)
Tags
  • cf_hocon - setup value for this field from hocon
  • cf_default - setup default value for this field
  • cf_env - setup value from env variable by name in this tag
  • cf_yaml - setup value for this field from yaml (version > 0.6)
  • cf_json - setup value for this field from json (version > 0.5)
  • cf_server - setup value from configuration server like spring cloud config server or others (version>0.7)
  • cf_vault - setup secret for this field from hashi corp vault (version>0.8)

Running configuring by smart variant

For Run configuration by smart variant autostart analysing of using tags. library will start configuring your structure by pipeline with all founded tags.

type Test struct {
    MyValue1 string `cf_default:"turur" cf_hocon:"mySourceValue1"`
    MySlice1 []bool `cf_default:"true,false,false,true" cf_env:"MY_SIGNALS"`
}

// in this example do use 3 tags: cf_default (using default values which setup inline tag)
// cf_env - using environment variable
// cf_hocon - using hocon source file 

//....

func myConfigurator() {
    myStruct, errConfiguring := gostructir.ConfigureSmart(&Test{}, "testhocon.hocon")
    // check errConfiguring for any errors
    if errConfiguring != nil {
        /// action for error
    }

    // cast interface{} into Test structure
    myValues := myStruct.(*Test)
    // now, u structure already filled
} 

Running configuring by setup

You can also setting configuring pipeline like this:

type Test struct {
    MyValue1 string `cf_default:"turur" cf_hocon:"mySourceValue1"`
    MySlice1 []bool `cf_default:"true,false,false,true" cf_env:"MY_SIGNALS"`
}

func myConfigurator() {
    myStruct, errConfiguring := gostructir.ConfigureSetup(&Test{}, "testhocon.hocon", []infra.FuncType{
        infra.FunctionSetupEnvironment,
    })// you should setup only by order configure
    // check errConfiguring for any errors
    if errConfiguring != nil {
        /// action for error
    }

    // cast interface{} into Test structure
    myValues := myStruct.(*Test)
    // now, u structure already filled
} 

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangeLogFormatter added in v0.4.3

func ChangeLogFormatter(formatter logrus.Formatter)

ChangeLogFormatter - changing current formatter

func ChangeLogLevel added in v0.4.3

func ChangeLogLevel(logLevel logrus.Level)

ChangeLogLevel - changing current loggin level

func ConfigureEasy

func ConfigureEasy(
	structure interface{},
	fileName string) (interface{}, error)

ConfigureEasy - default pipeline setup for configure your structure

func ConfigureSetup

func ConfigureSetup(
	structure interface{},
	fileName string,
	prefix string,
	functions []infra.FuncType) (interface{}, error)

ConfigureSetup - pipeline with your settings stages for your structure

func ConfigureSmart

func ConfigureSmart(
	structure interface{},
	fileName string,
) (interface{}, error)

ConfigureSmart - configuring by analysing tags for add prefer strategy for configuring

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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