config_selector

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2020 License: MIT Imports: 4 Imported by: 0

README

config_selector

Configuration file selector for go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigFileSelector

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

ConfigFileSelector is an a helper object. It provides some methods to easy find required configuration file specified by name Literal form initialisation:

configSelector = &ConfigFileSelector{filename, LookupPlacesList{CurrentPath, HomeDir}}

Additionally you can use NewConfigFileSelector constructor:

configSelector = NewConfigFileSelector(filename, CurrentPath, HomeDir)

func NewConfigFileSelector

func NewConfigFileSelector(fileName string, a ...LookupPlace) *ConfigFileSelector
ConfigFileSelector constructor

Allow to make new instance passing required filename and set of lookup places objects

func (*ConfigFileSelector) AddLookupPlace

func (s *ConfigFileSelector) AddLookupPlace(place LookupPlace)

AddLookupPlace allow to add additional lookup place runtime

func (*ConfigFileSelector) GetLookupPlaces added in v0.3.1

func (s *ConfigFileSelector) GetLookupPlaces() LookupPlacesList

Get lookup places keys list. Useful to check some place is in list or to call configFileSelector.GetLookupPlaces().String()

func (*ConfigFileSelector) IsFileExists

func (s *ConfigFileSelector) IsFileExists(path string) (bool, error)

Check if file specified by full path is exists

func (*ConfigFileSelector) LookupFilePathList

func (s *ConfigFileSelector) LookupFilePathList() (*[]string, error)

Get possible configuration file path list using lookup places in order set by lookup flags

func (*ConfigFileSelector) LookupFolderList

func (s *ConfigFileSelector) LookupFolderList() (*[]string, error)

LookupFolderList just return list of absolute path string if such path exists. All runtime calculated path are resolved here Returns a list of well-known directories in order set by lookup flags and consequent additions

func (*ConfigFileSelector) SelectFirstKnownPlace

func (s *ConfigFileSelector) SelectFirstKnownPlace() (*string, error)

Get first existing configuration file path from places set by lookup flags

func (*ConfigFileSelector) SelectPath

func (s *ConfigFileSelector) SelectPath(configPath string) (*string, error)

Find configuration file in requested path first or in well known path list defined by lookup flags return error if no such file found either in requested path or in well known path list. Possible variants: - empty path requested: search set (default) filename in defined lookup places, return first existed or error - filename requested: search specified filename in defined lookup places, return first existed or error - absolute path requested: return it (if exists) otherwise return error

func (*ConfigFileSelector) String

func (s *ConfigFileSelector) String() string

ConfigFileSelector instance implements Stringer interface:

configSelector.String() == "ConfigFileSelector{filename.conf, [./, Home]}

func (*ConfigFileSelector) UseEtc added in v0.3.0

func (s *ConfigFileSelector) UseEtc()

UseEtc adds /etc/ path to ConfigFileSelector lookup places list

func (*ConfigFileSelector) UseEtcProgramFolder added in v0.3.0

func (s *ConfigFileSelector) UseEtcProgramFolder(programName string)

UseEtcProgramFolder allow to add /etc/<program name>/ path to ConfigFileSelector lookup places list

type LookupPlace

type LookupPlace string

LookupPlace type is just a string

const (
	// Home is a platform dependent user home folder. Actual place detected runtime
	HomeDir LookupPlace = "Home"
	// UserConfig dir is a platform dependent user configuration path. Actual place detected runtime
	UserConfig LookupPlace = ".config"
	// Current work dir
	CurrentPath LookupPlace = "./"
	// Posix platforms /etc/
	Etc LookupPlace = "/etc"
)

Some lookup places predefined. Constant lookup places has special meanings which actual path calculated runtime. All others will threat as relative or absolute path

type LookupPlacesList added in v0.3.1

type LookupPlacesList []LookupPlace

Lookup places stored together in simple slice

func (*LookupPlacesList) String added in v0.3.1

func (s *LookupPlacesList) String() string

LookupPlacesList has it's own String method, it useful to output lookup places list, separated by comma's

Jump to

Keyboard shortcuts

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