config

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

README

TFCloud Go Config

Go package for config. Inspired by OpenStack oslo.config library.

Usage

Install package

go get github.com/tfcloud-go/config

Register configurations

// conf/server.go

package conf

// ...

var CONF = config.CONF

func init() {
	group := config.NewOptGroup("server")
	CONF.RegisterGroup(group)

	host := config.NewStrOpt("host").WithDefault("127.0.0.1")
	port := config.NewIntOpt("port").WithDefault(8080)
	CONF.RegisterOpts(group, host, port)
}

Parse configurations

// main.go

package main

// ...

var CONF = config.CONF

func main() {
	// ...

	CONF.ParseFile("your_config_file_name.conf")

	// ...
}

Get configuration value

// foo/server.go

package foo

// ...

var CONF = config.CONF

func startServer() {
	host := CONF.GetString("server", "host")
	port, _ := CONF.GetInt("server", "port")
	addr := net.JoinHostPort(host, port)

	// ...
}

Use configuration file

foo-server --config your_config_file_name.conf

The TFCloud Go Team. Apache License 2.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CONF = newConfigOpts()

Functions

This section is empty.

Types

type BoolOpt

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

func NewBoolOpt

func NewBoolOpt(name string) *BoolOpt

func (*BoolOpt) Default

func (o *BoolOpt) Default() bool

func (*BoolOpt) Name

func (o *BoolOpt) Name() string

func (*BoolOpt) WithDefault

func (o *BoolOpt) WithDefault(value bool) *BoolOpt

type ConfigOpts

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

func (*ConfigOpts) Get

func (c *ConfigOpts) Get(group, option string) string

func (*ConfigOpts) GetBool

func (c *ConfigOpts) GetBool(group, option string) (bool, error)

func (*ConfigOpts) GetFloat added in v0.3.0

func (c *ConfigOpts) GetFloat(group, option string) (float64, error)

func (*ConfigOpts) GetInt

func (c *ConfigOpts) GetInt(group, option string) (int, error)

func (*ConfigOpts) GetList

func (c *ConfigOpts) GetList(group, option string) []string

func (*ConfigOpts) GetString

func (c *ConfigOpts) GetString(group, option string) string

func (*ConfigOpts) GetURI added in v0.2.0

func (c *ConfigOpts) GetURI(group, option string) (url.URL, error)

func (*ConfigOpts) ParseFile

func (c *ConfigOpts) ParseFile(file string) error

func (*ConfigOpts) RegisterGroup

func (c *ConfigOpts) RegisterGroup(group *OptGroup)

func (*ConfigOpts) RegisterOpt

func (c *ConfigOpts) RegisterOpt(group *OptGroup, opt interface{})

func (*ConfigOpts) RegisterOpts

func (c *ConfigOpts) RegisterOpts(group *OptGroup, opts ...interface{})

type FloatOpt added in v0.3.0

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

func NewFloatOpt added in v0.3.0

func NewFloatOpt(name string) *FloatOpt

func (*FloatOpt) Default added in v0.3.0

func (o *FloatOpt) Default() float64

func (*FloatOpt) Name added in v0.3.0

func (o *FloatOpt) Name() string

func (*FloatOpt) WithDefault added in v0.3.0

func (o *FloatOpt) WithDefault(value float64) *FloatOpt

type IntOpt

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

func NewIntOpt

func NewIntOpt(name string) *IntOpt

func (*IntOpt) Default

func (o *IntOpt) Default() int

func (*IntOpt) Name

func (o *IntOpt) Name() string

func (*IntOpt) WithDefault

func (o *IntOpt) WithDefault(value int) *IntOpt

type ListOpt

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

func NewListOpt

func NewListOpt(name string) *ListOpt

func (*ListOpt) Default

func (o *ListOpt) Default() []string

func (*ListOpt) Name

func (o *ListOpt) Name() string

func (*ListOpt) WithDefault

func (o *ListOpt) WithDefault(first string, others ...string) *ListOpt

type OptGroup

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

func NewOptGroup

func NewOptGroup(name string) *OptGroup

func (*OptGroup) Name

func (g *OptGroup) Name() string

func (*OptGroup) String

func (g *OptGroup) String() string

type StrOpt

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

func NewStrOpt

func NewStrOpt(name string) *StrOpt

func (*StrOpt) Default

func (o *StrOpt) Default() string

func (*StrOpt) Name

func (o *StrOpt) Name() string

func (*StrOpt) WithDefault

func (o *StrOpt) WithDefault(value string) *StrOpt

type URIOpt added in v0.2.0

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

func NewURIOpt added in v0.2.0

func NewURIOpt(name string) *URIOpt

func (*URIOpt) Default added in v0.2.0

func (o *URIOpt) Default() *url.URL

func (*URIOpt) Name added in v0.2.0

func (o *URIOpt) Name() string

func (*URIOpt) WithDefault added in v0.2.0

func (o *URIOpt) WithDefault(value url.URL) *URIOpt

Jump to

Keyboard shortcuts

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