Documentation ¶
Index ¶
- Constants
- Variables
- func BuildQuery(cqr types.ConfigQueryResolver) string
- func ColorFormatTree(rootNode *ContainerNode, withValues bool) string
- func ColorizeToken(value string, tokenType NodeTokenType) string
- func ColorizeValue(value string, isEnum bool) string
- func CreateEnumFormatter(names []string) types.EnumFormatter
- func GetConfigFieldString(config r.Value, field FieldInfo) (value string, err error)
- func GetConfigPropFromString(structType r.Type, value string) (r.Value, error)
- func GetConfigPropString(propPtr r.Value) (string, error)
- func GetConfigQueryResolver(config types.ServiceConfig) types.ConfigQueryResolver
- func GetServiceConfig(service types.Service) types.ServiceConfig
- func IsNumber(value string) bool
- func ParseBool(value string, defaultValue bool) (parsedValue bool, ok bool)
- func PrintBool(value bool) string
- func SetConfigField(config r.Value, field FieldInfo, inputValue string) (valid bool, err error)
- type ContainerNode
- type EnumFormatter
- type FieldInfo
- type Node
- type NodeTokenType
- type PropKeyResolver
- func (pkr *PropKeyResolver) Bind(config types.ServiceConfig) PropKeyResolver
- func (pkr *PropKeyResolver) Get(key string) (string, error)
- func (pkr *PropKeyResolver) IsDefault(key string, value string) bool
- func (pkr *PropKeyResolver) KeyIsPrimary(key string) bool
- func (pkr *PropKeyResolver) QueryFields() []string
- func (pkr *PropKeyResolver) Set(key string, value string) error
- func (pkr *PropKeyResolver) SetDefaultProps(config types.ServiceConfig) error
- func (pkr *PropKeyResolver) UpdateConfigFromParams(config types.ServiceConfig, params *types.Params) error
- type ValueNode
Constants ¶
const EnumInvalid = -1
EnumInvalid is the constant value that an enum gets assigned when it could not be parsed
Variables ¶
var ColorizeContainer = ColorizeDesc
ColorizeContainer colorizes the input string as "Container"
var ColorizeDesc = color.New(color.FgHiBlack).SprintFunc()
ColorizeDesc colorizes the input string as "Description"
var ColorizeEnum = color.New(color.FgHiCyan).SprintFunc()
ColorizeEnum colorizes the input string as "Enum"
var ColorizeError = ColorizeFalse
ColorizeError colorizes the input string as "Error"
var ColorizeFalse = color.New(color.FgHiRed).SprintFunc()
ColorizeFalse colorizes the input string as "False"
var ColorizeNumber = color.New(color.FgHiBlue).SprintFunc()
ColorizeNumber colorizes the input string as "Number"
var ColorizeProp = color.New(color.FgHiMagenta).SprintFunc()
ColorizeProp colorizes the input string as "Prop"
var ColorizeString = color.New(color.FgHiYellow).SprintFunc()
ColorizeString colorizes the input string as "String"
var ColorizeTrue = color.New(color.FgHiGreen).SprintFunc()
ColorizeTrue colorizes the input string as "True"
Functions ¶
func BuildQuery ¶
func BuildQuery(cqr types.ConfigQueryResolver) string
BuildQuery converts the fields of a config object to a delimited query string
func ColorFormatTree ¶ added in v0.4.2
func ColorFormatTree(rootNode *ContainerNode, withValues bool) string
ColorFormatTree returns a color highlighted string representation of a node tree
func ColorizeToken ¶ added in v0.4.2
func ColorizeToken(value string, tokenType NodeTokenType) string
ColorizeToken colorizes the value according to the tokenType
func ColorizeValue ¶
ColorizeValue colorizes the input string according to what type appears to be
func CreateEnumFormatter ¶
func CreateEnumFormatter(names []string) types.EnumFormatter
CreateEnumFormatter creates a EnumFormatter struct
func GetConfigFieldString ¶
GetConfigFieldString serializes the config field value to a string representation
func GetConfigPropFromString ¶ added in v0.4.2
GetConfigPropFromString deserializes a config property from a string representation using the ConfigProp interface
func GetConfigPropString ¶ added in v0.4.2
GetConfigPropString serializes a config property to a string representation using the ConfigProp interface
func GetConfigQueryResolver ¶
func GetConfigQueryResolver(config types.ServiceConfig) types.ConfigQueryResolver
GetConfigQueryResolver returns the config itself if it implements ConfigQueryResolver otherwise it creates and returns a PropKeyResolver that implements it
func GetServiceConfig ¶ added in v0.4.2
func GetServiceConfig(service types.Service) types.ServiceConfig
GetServiceConfig returns the inner config of a service
func ParseBool ¶
ParseBool returns true for "1","true","yes" or false for "0","false","no" or defaultValue for any other value
Types ¶
type ContainerNode ¶ added in v0.4.2
ContainerNode is a Node with child items
func GetConfigFormat ¶
func GetConfigFormat(config types.ServiceConfig) *ContainerNode
GetConfigFormat returns type and field information about a ServiceConfig
func GetServiceConfigFormat ¶
func GetServiceConfigFormat(service types.Service) *ContainerNode
GetServiceConfigFormat returns type and field information about a ServiceConfig, resolved from it's Service
func (*ContainerNode) Field ¶ added in v0.4.2
func (n *ContainerNode) Field() *FieldInfo
Field returns the inner FieldInfo
func (*ContainerNode) TokenType ¶ added in v0.4.2
func (n *ContainerNode) TokenType() NodeTokenType
TokenType always returns ContainerToken for ContainerNode
func (*ContainerNode) Update ¶ added in v0.4.2
func (n *ContainerNode) Update(tv r.Value)
Update updates the items to match the provided value
type EnumFormatter ¶
type EnumFormatter struct {
// contains filtered or unexported fields
}
EnumFormatter is the helper methods for enum-like types
func (EnumFormatter) Names ¶
func (ef EnumFormatter) Names() []string
Names is the list of the valid Enum string values
func (EnumFormatter) Parse ¶
func (ef EnumFormatter) Parse(s string) int
Parse takes an enum mapped string and returns it's int representation or EnumInvalid (-1)
func (EnumFormatter) Print ¶
func (ef EnumFormatter) Print(e int) string
Print takes a enum mapped int and returns it's string representation or "Invalid"
type FieldInfo ¶
type FieldInfo struct { Name string Type r.Type EnumFormatter types.EnumFormatter Description string DefaultValue string Template string Required bool Title bool Base int Keys []string }
FieldInfo is the meta data about a config field
type Node ¶ added in v0.4.2
type Node interface { Field() *FieldInfo TokenType() NodeTokenType Update(tv r.Value) }
Node is the generic config tree item
type NodeTokenType ¶ added in v0.4.2
type NodeTokenType int
NodeTokenType is used to represent the type of value that a node has for syntax highlighting
const ( // UnknownToken represents all unknown/unspecified tokens UnknownToken NodeTokenType = iota // NumberToken represents all numbers NumberToken // StringToken represents strings and keys StringToken // EnumToken represents enum values EnumToken // TrueToken represent boolean true TrueToken // FalseToken represent boolean false FalseToken // PropToken represent a serializable struct prop PropToken // ErrorToken represent a value that was not serializable or otherwise invalid ErrorToken // ContainerToken is used for Array/Slice and Map tokens ContainerToken )
type PropKeyResolver ¶
type PropKeyResolver struct {
// contains filtered or unexported fields
}
PropKeyResolver implements the ConfigQueryResolver interface for services that uses key tags for query props
func NewPropKeyResolver ¶
func NewPropKeyResolver(config types.ServiceConfig) PropKeyResolver
NewPropKeyResolver creates a new PropKeyResolver and initializes it using the provided config
func (*PropKeyResolver) Bind ¶
func (pkr *PropKeyResolver) Bind(config types.ServiceConfig) PropKeyResolver
Bind is called to set the internal config reference for the PropKeyResolver
func (*PropKeyResolver) Get ¶
func (pkr *PropKeyResolver) Get(key string) (string, error)
Get returns the value of a config property tagged with the corresponding key
func (*PropKeyResolver) IsDefault ¶ added in v0.4.2
func (pkr *PropKeyResolver) IsDefault(key string, value string) bool
IsDefault returns whether the specified key value is the default value
func (*PropKeyResolver) KeyIsPrimary ¶
func (pkr *PropKeyResolver) KeyIsPrimary(key string) bool
KeyIsPrimary returns whether the key is the primary (and not an alias)
func (*PropKeyResolver) QueryFields ¶
func (pkr *PropKeyResolver) QueryFields() []string
QueryFields returns a list of tagged keys
func (*PropKeyResolver) Set ¶
func (pkr *PropKeyResolver) Set(key string, value string) error
Set sets the value of it's bound struct's property, tagged with the corresponding key
func (*PropKeyResolver) SetDefaultProps ¶ added in v0.4.0
func (pkr *PropKeyResolver) SetDefaultProps(config types.ServiceConfig) error
SetDefaultProps mutates the provided config, setting the tagged fields with their default values
func (*PropKeyResolver) UpdateConfigFromParams ¶
func (pkr *PropKeyResolver) UpdateConfigFromParams(config types.ServiceConfig, params *types.Params) error
UpdateConfigFromParams mutates the provided config, updating the values from it's corresponding params
type ValueNode ¶ added in v0.4.2
ValueNode is a Node without any child items
func (*ValueNode) TokenType ¶ added in v0.4.2
func (n *ValueNode) TokenType() NodeTokenType
TokenType returns a NodeTokenType that matches the value