util

package
v0.0.0-...-70e7e0d Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Repositories is the default directory for repositories.
	Repositories = "repositories"

	// DefaultLanguage is intentionally undefined.
	DefaultLanguage = ""
)
View Source
const (
	PathSeparator = "."

	EscapedPathSeparator = "\\" + PathSeparator

	InsertIndex = -1
)

Variables

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

func DeleteFromSlicePtr(parentSlice interface{}, index int) error

DeleteFromSlicePtr deletes an entry at index from the parent, which must be a slice ptr.

func DiffYAML

func DiffYAML(a, b string) (string, error)

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.

  1. The default path is the zero value, indicating "no config path available", and users of this package should act accordingly.
  2. ~/.config/dubbo if it exists (can be expanded: user has a home dir)
  3. 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 FileExists(file string) bool

func FileNameWithoutExt

func FileNameWithoutExt(file string) string

FileNameWithoutExt returns a file name without suffix.

func FormatterFilter

func FormatterFilter(input string) string

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

func IsKVPathElement(pe string) bool

IsKVPathElement report whether pe is a key/value path element.

func IsMap

func IsMap(value interface{}) bool

IsMap reports whether value is a map type.

func IsNPathElement

func IsNPathElement(pe string) bool

IsNPathElement report whether pe is an index path element.

func IsNilOrInvalidValue

func IsNilOrInvalidValue(v reflect.Value) bool

IsNilOrInvalidValue reports whether v is nil or reflect.Zero.

func IsSlice

func IsSlice(value interface{}) bool

IsSlice reports whether value is a slice type.

func IsSliceInterfacePtr

func IsSliceInterfacePtr(v interface{}) bool

IsSliceInterfacePtr reports whether v is a slice ptr type.

func IsVPathElement

func IsVPathElement(pe string) bool

IsVPathElement report whether pe is a value path element.

func IsValidPathElement

func IsValidPathElement(pe string) bool

IsValidPathElement reports whether pe is a valid path element.

func IsValueMap

func IsValueMap(v reflect.Value) bool

IsValueMap reports whether v is a map type.

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 IsValuePtr

func IsValuePtr(v reflect.Value) bool

IsValuePtr reports whether v is a ptr type.

func IsValueScalar

func IsValueScalar(v reflect.Value) bool

IsValueScalar reports whether v is a scalar type.

func IsValueSlice

func IsValueSlice(v reflect.Value) bool

IsValueSlice reports whether v is a slice type.

func IsValueStruct

func IsValueStruct(v reflect.Value) bool

IsValueStruct reports whether v is a struct type.

func IsYAMLEmpty

func IsYAMLEmpty(y string) bool

IsYAMLEmpty reports whether the YAML string y is logically empty.

func JoinYAML

func JoinYAML(segs []string) string

JoinYAML use "---" to join yaml segments.

func LicenseFilter

func LicenseFilter(input string) string

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

func LoadTemplate(path, file, builtin string) (string, error)

LoadTemplate gets template content by the specified file.

func NewSortedSet

func NewSortedSet() *sortedSet

func OverlayYAML

func OverlayYAML(base, overlay string) (string, error)

OverlayYAML patches the overlay tree over the base tree and returns the result. All trees are expressed as YAML strings.

func PathKV

func PathKV(pe string) (k, v string, err error)

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

func PathN(pe string) (int, error)

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

func PathV(pe string) (string, error)

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

func RemoveBrackets(pe string) (string, bool)

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 ReserveEoFSpaceFilter(input string) string

func SetLabel

func SetLabel(resource runtime.Object, label, value string) error

SetLabel is a helper function which sets the specified label and value on the specified object.

func SpaceFilter

func SpaceFilter(input string) string

SpaceFilter removes all leading and trailing space.

func SpaceLineFilter

func SpaceLineFilter(input string) string

SpaceLineFilter removes all space lines.

func SplitYAML

func SplitYAML(y string) ([]string, error)

SplitYAML uses yaml separator that begins with "---" to split yaml file.

func TestYAMLEqual

func TestYAMLEqual(golden, result string) (bool, string, error)

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 ToString

func ToString(errors []error, separator string) string

func ValidateApplicationName

func ValidateApplicationName(name string) error

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 Errors

type Errors []error

func AppendErr

func AppendErr(errors []error, err error) Errors

func AppendErrs

func AppendErrs(errors []error, newErrs []error) Errors

func NewErrs

func NewErrs(err error) Errors

func (Errors) Error

func (e Errors) Error() string

func (Errors) ToErrors

func (e Errors) ToErrors() error

type FilterFunc

type FilterFunc func(string) string

FilterFunc is used to filter some contents of manifest.

type Path

type Path []string

Path is a path in slice form.

func PathFromString

func PathFromString(path string) Path

PathFromString converts a string path of form a.b.c to a string slice representation.

func ToYAMLPath

func ToYAMLPath(path string) Path

ToYAMLPath converts a path string to path such that the first letter of each path element is lower case.

func (Path) Equals

func (p Path) Equals(p2 Path) bool

func (Path) String

func (p Path) String() string

String converts a string slice path representation of form ["a", "b", "c"] to a string representation like "a.b.c".

Directories

Path Synopsis
log

Jump to

Keyboard shortcuts

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