verdeter

package module
v0.0.0-...-8fb0621 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: MPL-2.0 Imports: 11 Imported by: 2

README

Verdeter project

verdeter project is a tool to write configuration easily with cobra and viper.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CheckNotEmpty = func(val interface{}) bool {
	strVal, ok := val.(string)
	ret := ok && strVal != ""
	if !ret {
		fmt.Printf("Error: empty value is not allowed")
	}
	return ret
}

CheckNotEmpty is a helper function to check a string value is not empty

View Source
var CheckTCPHighPort = func(val interface{}) bool {
	intVal, ok := val.(int)
	if ok {
		return intVal >= 1024 && intVal <= 65535
	}
	fmt.Printf("Error: value (%d) is not a TCP high port (between 1024 and 65535) \n", intVal)
	return false
}

CheckTCPHighPort is a helper function to verify a port is tcp high port

View Source
var TrimToLower = func(val interface{}) interface{} {
	strVal, ok := val.(string)
	if ok {
		return strings.ToLower(strings.TrimSpace(strVal))
	}
	return val
}

TrimToLower is a helper function to normalize value

Functions

func AmIRoot

func AmIRoot() bool

AmIRoot returns is the process owner is root

func CreateDirectory

func CreateDirectory(path string) error

func CreateWritableDirectory

func CreateWritableDirectory(path string) bool

func DirectoryExist

func DirectoryExist(path string) bool

func DirectoryWritable

func DirectoryWritable(path string) bool

func ErrorAndHelp

func ErrorAndHelp(cfg *ConfigCmd, err string)

ErrorAndHelp print error and help

func ExpandPath

func ExpandPath(rootPath, path interface{}) interface{}

func FileExist

func FileExist(path string) bool

func GetHomeDirectory

func GetHomeDirectory() string

func GetOffset

func GetOffset() int

GetOffset :

func GetUniqueInterface

func GetUniqueInterface() (string, error)

func GetWorkingDir

func GetWorkingDir() string

GetWorkingDir Returns the current Working Dir

func InitConfig

func InitConfig(c *ConfigCmd)

InitConfig init Config management

func Key

func Key(cmd *cobra.Command, name string, valType ConfigType, short string, usage string, global bool) error

Key defines a flag in cobra bound to env and files

func Run

func Run(sub *ConfigCmd, runf func(cfg *ConfigCmd, args []string)) func(*cobra.Command, []string)

Run :

func SetLogFile

func SetLogFile(appName string)

SetLogFile set the file to use for application logging (use working directory if the directory defined in the configuration can not be read nor created)

Types

type ConfigCmd

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

ConfigCmd allows configuration

func NewConfigCmd

func NewConfigCmd(use string, shortDesc string, longDesc string, runf func(cfg *ConfigCmd, args []string)) *ConfigCmd

NewConfigCmd is the constructor for Config

func (*ConfigCmd) AddConfig

func (c *ConfigCmd) AddConfig(sub *ConfigCmd)

AddConfig adds a sub configuration

func (ConfigCmd) CallSubRun

func (c ConfigCmd) CallSubRun(subName string)

CallSubRun :

func (*ConfigCmd) Execute

func (c *ConfigCmd) Execute()

Execute Configuration (call it only for root command)

func (*ConfigCmd) GKey

func (c *ConfigCmd) GKey(name string, valType ConfigType, short string, usage string) error

GKey defines a flag in cobra bound to env and config file

func (*ConfigCmd) GetAppName

func (c *ConfigCmd) GetAppName() string

GetAppName :

func (*ConfigCmd) GetComputedValue

func (c *ConfigCmd) GetComputedValue() map[string]func() interface{}

GetComputedValue sets a value dynamically as the default for a key

func (*ConfigCmd) GetInstanceName

func (c *ConfigCmd) GetInstanceName() string

GetInstanceName :

func (*ConfigCmd) Initialize

func (c *ConfigCmd) Initialize()

Initialize handle initial configuration

func (*ConfigCmd) LKey

func (c *ConfigCmd) LKey(name string, valType ConfigType, short string, usage string) error

LKey defines a flag in cobra bound to env and config file

func (*ConfigCmd) SetCheck

func (c *ConfigCmd) SetCheck(name string, isValid func(interface{}) bool)

SetCheck : function to valid the value of a config key

func (*ConfigCmd) SetComputedValue

func (c *ConfigCmd) SetComputedValue(name string, fval func() interface{})

SetComputedValue sets a value dynamically as the default for a key

func (*ConfigCmd) SetConstraint

func (c *ConfigCmd) SetConstraint(msg string, constraint func() bool)

SetConstraint sets a constraint

func (*ConfigCmd) SetDefault

func (c *ConfigCmd) SetDefault(name string, value interface{})

SetDefault : set default value for a key

func (*ConfigCmd) SetNbArgs

func (c *ConfigCmd) SetNbArgs(nb int)

SetNbArgs : function to fix the number of args

func (*ConfigCmd) SetNormalize

func (c *ConfigCmd) SetNormalize(name string, normalize func(interface{}) interface{})

SetNormalize : function to normalize the value of a config Key (if set)

func (*ConfigCmd) SetRequired

func (c *ConfigCmd) SetRequired(name string)

SetRequired sets a key as required

func (*ConfigCmd) ValidOK

func (c *ConfigCmd) ValidOK() bool

ValidOK checks if config keys have valid values

type ConfigType

type ConfigType int

ConfigType type used in key definitions

const (
	IsStr ConfigType
	IsInt
	IsBool
)

Jump to

Keyboard shortcuts

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