config

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2020 License: BSD-3-Clause Imports: 3 Imported by: 0

README

Go with Config

Modular configuration management in Go, redesigned.

Documentation

Overview

Go with Config

Modular configuration management in Go, redesigned.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Modules []*Module
}

Type Config defines a manager of modular configuration. It is a struct with Modules property as a slice of Module pointer.

func New added in v1.0.1

func New() *Config

Creates a new Config pointer.

func (*Config) AppendModule

func (config *Config) AppendModule(module *Module) *Config

Appends a module configuration to the Config pointer and returns the Config pointer for chain-able functions call purposes.

func (*Config) CreateModule

func (config *Config) CreateModule(name string) *Module

Creates a named module configuration, appends it to the Config, and returns the Module pointer.

func (*Config) DeleteModule

func (config *Config) DeleteModule(name string) *Config

Deletes a named module configuration from the Config pointer and returns the Config pointer for chain-able functions call purposes.

func (*Config) IsModuleExists

func (config *Config) IsModuleExists(name string) bool

Checks whether a named module configuration is exists in the Modules slice in the Config pointer. Returns true if the named module is exists, and false otherwise.

func (*Config) OnModule

func (config *Config) OnModule(name string) *Module

Get a named module configuration from the Config pointer. If the module configuration with specified name does not exist in the Config's Modules slice, it will then try to create a new Module with that name, so that the returns value is predicted will not be nil. Returns a Module pointer.

type Module

type Module struct {
	Name   string
	Config map[string]string
}

Type Module defines a named modular configuration.

Property Name defines the Module's Name as string.
Property Config defines the key-value pair of configuration list as map string
of string.

func NewModule

func NewModule(name string) *Module

func (*Module) Delete

func (module *Module) Delete(key string) *Module

Delete module configuration with specified key. Returns the Module for function call chaining purpose.

func (*Module) Get

func (module *Module) Get(key string) string

Get module configuration with specified key. Returns the string value of the module configuration. When no configuration is saved with that specified key, it will returns an empty string.

func (*Module) GetWithDefault

func (module *Module) GetWithDefault(key string, defaultValue string) string

The same as Get(key string), but it will returns defaultValue instead of empty string when no configuration is saved with that specified key.

func (*Module) Set

func (module *Module) Set(key string, value string) *Module

Set module configuration with specified key to a specified value. Returns the Module for function call chaining purpose.

Jump to

Keyboard shortcuts

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