helper

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnderscoreConnector string = "_"
	DotConnector        string = "."
	HyphenConnector     string = "-"
)

Variables

This section is empty.

Functions

func BoolPoint added in v1.3.0

func BoolPoint(b bool) *bool

func Contains added in v1.3.0

func Contains(arry []string, val string) (index int, flag bool)

Contains will return bool balue that whether the arry contains string val

func ConvertFlatMapToArray added in v1.3.0

func ConvertFlatMapToArray(flatMap map[string]interface{}, connector string) (outArray []string)

ConvertFlatMapToArray will return the request body converted from flatmap {"id":"xxx", "product.id":"xxxx", "managed":true} will be converted to ["{"id":"xxxx"}","{"product":{"id":"xxxx"}}",...]

func ConvertMapToJSONString added in v1.3.0

func ConvertMapToJSONString(inputMap map[string]interface{}) string

ConvertMapToJSONString converts the map to a json string.

func ConvertRequestBodyByAttr added in v1.3.0

func ConvertRequestBodyByAttr(inputString string, connector string) (outArray []string, err error)

ConvertRequestBodyByAttr will return the request bodies by attributes

func ConvertStringToInt added in v1.3.0

func ConvertStringToInt(mystring string) int

func ConvertStructToMap added in v1.3.0

func ConvertStructToMap(s interface{}) map[string]interface{}

func ConvertStructToString added in v1.3.0

func ConvertStructToString(s interface{}) string

func Dig added in v1.3.0

func Dig(object interface{}, keys []interface{}) interface{}

Dig Expose dig to used by others

func DigArray added in v1.3.0

func DigArray(object interface{}, keys ...interface{}) []interface{}

DigArray tries to find an array inside the given object with the given path, and returns its value. If there is no attribute with the given path then the test will be aborted with an error.

func DigBool added in v1.3.0

func DigBool(object interface{}, keys ...interface{}) bool

DigBool tries to find an attribute inside the given object with the given path, and returns its value, assuming that it is a boolean. For example, if the object is the result of parsing the following JSON document:

{
	"kind": "Cluster",
	"id": "123",
	"hasId": true,
	"flavour": {
		"kind": "Flavour",
		"hasId": false,
		"href": "/api/clusters_mgmt/v1/flavours/456"
	}
}

The the 'hasId' attribute can be obtained like this:

hasID := DigBool(object, "hasId")

And the 'hasId' attribute inside the 'flavour' can be obtained like this:

flavourHasID := DigBool(object, "flavour", "hasId")

If there is no attribute with the given path then the return value will be false.

func DigByConnector added in v1.3.0

func DigByConnector(object interface{}, key string) interface{}

func DigFloat added in v1.3.0

func DigFloat(object interface{}, keys ...interface{}) float64

DigFloat tries to find an attribute inside the given object with the given path, and returns its value, assuming that it is an floating point number. If there is no attribute with the given path then the test will be aborted with an error.

func DigInt added in v1.3.0

func DigInt(object interface{}, keys ...interface{}) int

DigInt tries to find an attribute inside the given object with the given path, and returns its value, assuming that it is an integer. If there is no attribute with the given path then the test will be aborted with an error.

func DigObject added in v1.3.0

func DigObject(object interface{}, keys ...interface{}) interface{}

DigObject tries to find an attribute inside the given object with the given path, and returns its value. If there is no attribute with the given path then the test will be aborted with an error.

func DigString added in v1.3.0

func DigString(object interface{}, keys ...interface{}) string

DigString tries to find an attribute inside the given object with the given path, and returns its value, assuming that it is an string. For example, if the object is the result of parsing the following JSON document:

{
	"kind": "Cluster",
	"id": "123",
	"flavour": {
		"kind": "Flavour",
		"id": "456",
		"href": "/api/clusters_mgmt/v1/flavours/456"
	}
}

The the 'id' attribute can be obtained like this:

clusterID := DigString(object, "id")

And the 'id' attribute inside the 'flavour' can be obtained like this:

flavourID := DigString(object, "flavour", "id")

If there is no attribute with the given path then the return value will be an empty string.

func DigStringArray added in v1.3.0

func DigStringArray(object interface{}, keys ...interface{}) []string

func EndsWith added in v1.3.0

func EndsWith(st string, substring string) (flag bool)

EndsWith will return the bool value that whether the st is end with substring

func FlatDetails added in v1.3.0

func FlatDetails(input []interface{}, connector string) map[string]interface{}

FlatInitialMap parses the data to store all the attributes at the first level.

func FlatInitialMap added in v1.3.0

func FlatInitialMap(inputMap map[string]interface{}, connector string) map[string]interface{}

FlatInitialMap parses the data to store all the attributes at the first level.

func FlatInterface added in v1.3.0

func FlatInterface(input []interface{}, outputMap map[string]interface{}, key string, connector string)

func FlatMap added in v1.3.0

func FlatMap(inputMap map[string]interface{}, outputMap map[string]interface{}, key string, connector string)

FlatMap parses the data, and stores all the attributes and the sub attributes at the same level with the prefix key.

func IsInMap added in v1.3.0

func IsInMap(inputMap map[string]interface{}, key string) bool

func IsSorted added in v1.3.0

func IsSorted(arry []string, mode string) (flag bool)

IsSorted will return whether the array is sorted by mode

func Join added in v1.3.0

func Join(s ...string) string

Join will link the strings with "."

func LookUpKey added in v1.3.0

func LookUpKey(sourceMap interface{}, key interface{}) (result interface{})

LookUpKey support find a key in a map

func LookUpKeys added in v1.3.0

func LookUpKeys(sourceMap interface{}, keys ...interface{}) (result interface{})

LookUpKeys support find keys that has not an abosolute path in a map

func Lstrip added in v1.3.0

func Lstrip(st string, substring string) string

Lstrip will return the string left striped with substring

func MapStructure added in v1.3.0

func MapStructure(m map[string]interface{}, i interface{}) error

MapStructure will map the map to the address of the structre *i

func Max added in v1.3.0

func Max(a int, b int) int

Min will return the minimize value

func Min added in v1.3.0

func Min(a int, b int) int

Min will return the minimize value

func MixCases added in v1.3.0

func MixCases(s string) string

MixCases converts a string of lowercase into a string of mixed case

func NegateBoolToString added in v1.3.0

func NegateBoolToString(value bool) string

NegateBoolToString reverts the boolean to its oppositely value as a string.

func NewRand added in v1.3.0

func NewRand() *rand.Rand

NewRand returns a rand with the time seed

func Parse added in v1.3.0

func Parse(data []byte) map[string]interface{}

Parse parses the given JSON data and returns a map of strings containing the result.

func Rstrip added in v1.3.0

func Rstrip(st string, substring string) string

Rstrip will return the string right striped with substring

func RunCMD added in v1.3.0

func RunCMD(cmd string) (stdout string, stderr string, err error)

func StartsWith added in v1.3.0

func StartsWith(st string, substring string) (flag bool)

StartsWith return bool whether st start with substring

func Strip added in v1.3.0

func Strip(st string, substring string) string

Strip will return the value striped with substring

func Template added in v1.3.0

func Template(source string, args ...interface{}) string

Template processes the given template using as data the set of name value pairs that are given as arguments. For example, to the following code:

result, err := Template(`
	{
		"name": "{{ .Name }}",
		"flavour": {
			"id": "{{ .Flavour }}"
		}
	}
	`,
	"Name", "mycluster",
	"Flavour", "4",
)

Produces the following result:

{
	"name": "mycluster",
	"flavour": {
		"id": "4"
	}
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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