8000 GitHub - specialfish9/confuso: A simple go project to read config
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

specialfish9/confuso

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

< 8855 button type="button" aria-label="Outline" aria-haspopup="true" aria-expanded="false" tabindex="0" class="prc-Button-ButtonBase-c50BI OverviewRepoFiles-module__ActionMenu_Button--xB9DS" data-loading="false" data-size="medium" data-variant="invisible" aria-describedby=":Rr9ab:-loading-announcement" id=":Rr9ab:">

confuso

A simple go project for reading configuration files

Features

  • Read your configuration from a file
  • Automatically resolve environment variables
  • Custom name for config fields

How to use it

  1. Add dependency
go get github.com/specialfish9/confuso
  1. Write your custom config struct, for example:
type Config struct {
	Db   Db
	Http Http
}

type Db struct {
	Host     string
	Port     int
	Username string
	Password string
	UseSsl   bool `confuso:"use_ssl"`
}

type Http struct {
	Hostname string `confuso:"website_hostname"`
	Port     int
}
  1. Write your matching config
# Database
Db.Host=${DB_HOSTNAME}
Db.Port=5432
Db.Username=admin
Db.Password=${DB_PASSWORD}
Db.use_ssl=true

# Http
Http.website_hostname=${HTTP_HOSTNAME}
Http.Port=${HTTP_PORT}
  1. Load it
var config = Config{}
err := confuso.LoadConf("myconf.whatev", &config)

if err != nil {
	log.Fatal(err)
}
  1. Enjoy!
fmt.Printf("My website is: %s!\n", config.Http.Port)

Integrations

Validator

You can integrate confuso with the validator package.

type UserConfig struct {
	Username string `validate:"min=3,max=40,regexp=^[a-zA-Z]*$"`
	Name string     `validate:"nonzero"`
	Password string `validate:"min=8"`
}

var userConfig = UserConfig{}
err := confuso.LoadConf("myconf.whatev", &userConfig)

if err != nil {
	log.Fatal(err)
}

if errs := validator.Validate(userConfig); errs != nil {
	// values not valid, deal with errors here
}

About

A simple go project to read config

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages

0