format

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const EnumInvalid = -1

EnumInvalid is the constant value that an enum gets assigned when it could not be parsed

Variables

View Source
var ColorizeDesc = color.New(color.FgHiBlack).SprintFunc()

ColorizeDesc colorizes the input string as "Description"

View Source
var ColorizeEnum = color.New(color.FgHiCyan).SprintFunc()

ColorizeEnum colorizes the input string as "Enum"

View Source
var ColorizeFalse = color.New(color.FgHiRed).SprintFunc()

ColorizeFalse colorizes the input string as "False"

View Source
var ColorizeNumber = color.New(color.FgHiBlue).SprintFunc()

ColorizeNumber colorizes the input string as "Number"

View Source
var ColorizeString = color.New(color.FgHiYellow).SprintFunc()

ColorizeString colorizes the input string as "String"

View Source
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 ColorizeValue

func ColorizeValue(value string, isEnum bool) string

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

func GetConfigFieldString(config reflect.Value, field FieldInfo) (value string, err error)

func GetConfigMap

func GetConfigMap(service types.Service) (map[string]string, int)

GetConfigMap returns a string map of a given Config struct

func GetConfigQueryResolver

func GetConfigQueryResolver(config types.ServiceConfig) types.ConfigQueryResolver

func IsNumber

func IsNumber(value string) bool

IsNumber returns whether the specified string is number-like

func ParseBool

func ParseBool(value string, defaultValue bool) (parsedValue bool, ok bool)

ParseBool returns true for "1","true","yes" or false for "0","false","no" or defaultValue for any other value

func PrintBool

func PrintBool(value bool) string

PrintBool returns "Yes" if value is true, otherwise returns "No"

func SetConfigField

func SetConfigField(config reflect.Value, field FieldInfo, inputValue string) (valid bool, err error)

Types

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          reflect.Type
	EnumFormatter types.EnumFormatter
	Description   string
	DefaultValue  string
	Template      string
	Required      bool
	Title         bool
	Keys          []string
}

func GetConfigFormat

func GetConfigFormat(serviceConfig types.ServiceConfig) (reflect.Type, []FieldInfo)

func GetServiceConfigFormat

func GetServiceConfigFormat(service types.Service) (reflect.Type, []FieldInfo)

type NotifyFormat

type NotifyFormat int

NotifyFormat describes the format used in the notification body

const (
	// Markdown is the default notification format
	Markdown NotifyFormat = 0
)

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

BindKeys is called to map config fields to it's tagged query keys

func (*PropKeyResolver) Bind

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) KeyIsPrimary

func (pkr *PropKeyResolver) KeyIsPrimary(key string) bool

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) 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

Jump to

Keyboard shortcuts

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