defaults

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2021 License: MIT Imports: 1 Imported by: 2

README

Defaults

This parser sets the given default values in the structs properties

Usage

func ReadConfig(rd io.Reader) Config {
	var conf Config

	if err := toml.Unmarshal(rd, conf); err != nil {
		panic(err)
	}

	if err := defaults.Parse(&conf); err != nil {
		panic(err)
	}

	return conf
}

type Config struct {
	Name 	string 	`default:"App"`
	Develop bool 	`default:"true"`
	DB 	DbConfig
}

type DbConfig struct {
	Driver 		 string `default:"postgres"`
	ConnectionString string
}

Documentation

Overview

Package defaults sets default values in your struct.

Usage

Create your struct that needs defaults

type Config struct {
	Name 	string 	`default:"App"`
	Develop bool 	`default:"true"`
	DB 	DbConfig
}

type DbConfig struct {
	Driver 		 string `defaults:"postgress"`
	ConnectionString string
}

And than read it:

func ReadConfig(rd io.Reader) Config {
	var conf Config

	if err := toml.Unmarshal(&conf) {
		panic(err)
	}

	if err := defaults.Parse(&conf) {
		panic(err)
	}

	return config
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(obj interface{}) error

Parse parses the given defaults from the default tag of a struct property

Types

This section is empty.

Jump to

Keyboard shortcuts

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