Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyFilters(input string, filters ...FilterFunc) string
- func CreatePaths() (err error)
- func DeleteFromMap(parentMap interface{}, key interface{}) error
- func DeleteFromSlicePtr(parentSlice interface{}, index int) error
- func DiffYAML(a, b string) (string, error)
- func Dir() (path string)
- func EffectivePath() (path string)
- func FileExists(file string) bool
- func FileNameWithoutExt(file string) string
- func FormatterFilter(input string) string
- func InChina() bool
- func InsertIntoMap(parentMap interface{}, key interface{}, value interface{}) error
- func InteractiveTerminal() bool
- func IsKVPathElement(pe string) bool
- func IsMap(value interface{}) bool
- func IsNPathElement(pe string) bool
- func IsNilOrInvalidValue(v reflect.Value) bool
- func IsSlice(value interface{}) bool
- func IsSliceInterfacePtr(v interface{}) bool
- func IsVPathElement(pe string) bool
- func IsValidPathElement(pe string) bool
- func IsValueMap(v reflect.Value) bool
- func IsValueNil(value interface{}) bool
- func IsValueNilOrDefault(value interface{}) bool
- func IsValuePtr(v reflect.Value) bool
- func IsValueScalar(v reflect.Value) bool
- func IsValueSlice(v reflect.Value) bool
- func IsValueStruct(v reflect.Value) bool
- func IsYAMLEmpty(y string) bool
- func JoinYAML(segs []string) string
- func LicenseFilter(input string) string
- func LoadTemplate(path, file, builtin string) (string, error)
- func NewSortedSet() *sortedSet
- func OverlayYAML(base, overlay string) (string, error)
- func PathKV(pe string) (k, v string, err error)
- func PathN(pe string) (int, error)
- func PathV(pe string) (string, error)
- func RemoveBrackets(pe string) (string, bool)
- func RepositoriesPath() string
- func ReserveEoFSpaceFilter(input string) string
- func SetLabel(resource runtime.Object, label, value string) error
- func SpaceFilter(input string) string
- func SpaceLineFilter(input string) string
- func SplitYAML(y string) ([]string, error)
- func TestYAMLEqual(golden, result string) (bool, string, error)
- func ToString(errors []error, separator string) string
- func ValidateApplicationName(name string) error
- type ErrInvalidApplicationName
- type Errors
- type FilterFunc
- type Path
Constants ¶
const ( // Repositories is the default directory for repositories. Repositories = "repositories" // DefaultLanguage is intentionally undefined. DefaultLanguage = "" )
const ( PathSeparator = "." EscapedPathSeparator = "\\" + PathSeparator InsertIndex = -1 )
Variables ¶
var ValidKeyRegex = regexp.MustCompile("^[a-zA-Z0-9_-]*$")
ValidKeyRegex is a regex for a valid path key element.
Functions ¶
func ApplyFilters ¶
func ApplyFilters(input string, filters ...FilterFunc) string
func CreatePaths ¶
func CreatePaths() (err error)
CreatePaths is a convenience function for creating the on-disk dubbo config structure. All operations should be tolerant of nonexistent disk footprint where possible (for example listing repositories should not require an extant path, but _adding_ a repository does require that the dubbo config structure exist. Current structure is: ~/.config/dubbo ~/.config/dubbo/repositories
func DeleteFromMap ¶
func DeleteFromMap(parentMap interface{}, key interface{}) error
DeleteFromMap deletes an entry with the given key parent, which must be a map.
func DeleteFromSlicePtr ¶
DeleteFromSlicePtr deletes an entry at index from the parent, which must be a slice ptr.
func DiffYAML ¶
DiffYAML accepts two single yaml(not with "---" yaml separator). Returns a string containing a line-by-line unified diff of the linewise changes required to make A into B. Each line is prefixed with '+', '-', or ' ' to indicate if it should be added, removed, or is correct respectively.
eg: a: key: val
key1: val1
b: key: val
key1: val2
return: key: val
-key1: val1 +key1: val2
func Dir ¶
func Dir() (path string)
Dir is derived in the following order, from lowest to highest precedence.
- The default path is the zero value, indicating "no config path available", and users of this package should act accordingly.
- ~/.config/dubbo if it exists (can be expanded: user has a home dir)
- The value of $XDG_CONFIG_PATH/dubbo if the environment variable exists.
The path is created if it does not already exist.
func EffectivePath ¶
func EffectivePath() (path string)
EffectivePath to use is that which was provided by --path or FUNC_PATH. Manually parses flags such that this can be used during (cobra/viper) flag definition (prior to parsing).
func FileExists ¶
func FileNameWithoutExt ¶
FileNameWithoutExt returns a file name without suffix.
func FormatterFilter ¶
FormatterFilter uses github.com/google/yamlfmt to format yaml file
func InChina ¶
func InChina() bool
InChina returns whether the current time is in China Standard Time.
func InsertIntoMap ¶
func InsertIntoMap(parentMap interface{}, key interface{}, value interface{}) error
InsertIntoMap inserts value with key into parent which must be a map, map ptr, or interface to map.
func InteractiveTerminal ¶
func InteractiveTerminal() bool
InteractiveTerminal returns whether or not the currently attached process terminal is interactive. Used for determining whether or not to interactively prompt the user to confirm default choices, etc.
func IsKVPathElement ¶
IsKVPathElement report whether pe is a key/value path element.
func IsNPathElement ¶
IsNPathElement report whether pe is an index path element.
func IsNilOrInvalidValue ¶
IsNilOrInvalidValue reports whether v is nil or reflect.Zero.
func IsSliceInterfacePtr ¶
func IsSliceInterfacePtr(v interface{}) bool
IsSliceInterfacePtr reports whether v is a slice ptr type.
func IsVPathElement ¶
IsVPathElement report whether pe is a value path element.
func IsValidPathElement ¶
IsValidPathElement reports whether pe is a valid path element.
func IsValueNil ¶
func IsValueNil(value interface{}) bool
IsValueNil returns true if either value is nil, or has dynamic type {ptr, map, slice} with value nil.
func IsValueNilOrDefault ¶
func IsValueNilOrDefault(value interface{}) bool
IsValueNilOrDefault returns true if either IsValueNil(value) or the default value for the type.
func IsValueScalar ¶
IsValueScalar reports whether v is a scalar type.
func IsValueSlice ¶
IsValueSlice reports whether v is a slice type.
func IsValueStruct ¶
IsValueStruct reports whether v is a struct type.
func IsYAMLEmpty ¶
IsYAMLEmpty reports whether the YAML string y is logically empty.
func LicenseFilter ¶
LicenseFilter assumes that license is at the beginning. So we just remove all the leading comments until the first non-comment line appears.
func LoadTemplate ¶
LoadTemplate gets template content by the specified file.
func NewSortedSet ¶
func NewSortedSet() *sortedSet
func OverlayYAML ¶
OverlayYAML patches the overlay tree over the base tree and returns the result. All trees are expressed as YAML strings.
func PathKV ¶
PathKV returns the key and value string parts of the entire key/value path element. It returns an error if pe is not a key/value path element.
func PathN ¶
PathN returns the index part of the entire value path element. It returns an error if pe is not an index path element.
func PathV ¶
PathV returns the value string part of the entire value path element. It returns an error if pe is not a value path element.
func RemoveBrackets ¶
RemoveBrackets removes the [] around pe and returns the resulting string. It returns false if pe is not surrounded by [].
func RepositoriesPath ¶
func RepositoriesPath() string
RepositoriesPath returns the full path at which to look for repositories. Use DUBBO_REPOSITORIES_PATH to override default.
func ReserveEoFSpaceFilter ¶
func SetLabel ¶
SetLabel is a helper function which sets the specified label and value on the specified object.
func SpaceFilter ¶
SpaceFilter removes all leading and trailing space.
func SpaceLineFilter ¶
SpaceLineFilter removes all space lines.
func TestYAMLEqual ¶
TestYAMLEqual judges whether golden and result yaml are the same and return the diff if they are different. If this function returns error, it means that golden file or result file could not be formatted. eg:
golden: line result: line return: true, "" golden: lineG result: lineR return: false, line 1 diff: --golden-- lineG --result-- lineR golden: line result: line lineAdd return: false, line 2 to 2: --result addition-- lineAdd
func ValidateApplicationName ¶
ValidateApplicationName validates that the input name is a valid function name, ie. valid DNS-1035 label. It must consist of lower case alphanumeric characters or '-' and start with an alphabetic character and end with an alphanumeric character. (e.g. 'my-name', or 'abc-1', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')
Types ¶
type ErrInvalidApplicationName ¶
type ErrInvalidApplicationName error
ErrInvalidApplicationName indicates the name did not pass function name validation.
type FilterFunc ¶
FilterFunc is used to filter some contents of manifest.
type Path ¶
type Path []string
Path is a path in slice form.
func PathFromString ¶
PathFromString converts a string path of form a.b.c to a string slice representation.
func ToYAMLPath ¶
ToYAMLPath converts a path string to path such that the first letter of each path element is lower case.