util

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Age

func Age(unixTime int64) string

Age returns a string representing the time elapsed since unixTime in the form "1d", "2h", "3m", or "4s".

func Clear

func Clear(v interface{})

func CombineManifests added in v1.3.0

func CombineManifests(yamls []string) string

func ComputeHmacSha256 added in v1.3.0

func ComputeHmacSha256(ak string, sk string) string

ComputeHmacSha256 According to ak/sk generate secret key

func ContainsChinese added in v1.9.9

func ContainsChinese(str string) bool

func ExtractImageName added in v1.9.9

func ExtractImageName(image string) string

Test case reference https://github.com/containers/image/blob/main/docker/reference/reference_test.go

func GeneReleaseName added in v1.9.9

func GeneReleaseName(namingRule, projectName, namespace, envName, service string) string

func GenerateTmpFile

func GenerateTmpFile() (string, error)

func GetAddress added in v1.2.0

func GetAddress(uri string) (string, error)

func GetBoolFromPointer added in v1.9.9

func GetBoolFromPointer(source *bool) bool

func GetBoolPointer added in v1.9.9

func GetBoolPointer(data bool) *bool

func GetDailyStartTimestamps added in v1.9.9

func GetDailyStartTimestamps(startTimestamp, endTimestamp int64) []int64

GetDailyStartTimestamps returns a slice of Unix timestamps representing the start of each day between startTimestamp and endTimestamp. It is worth mentioning that we will add an additional date timestamp just to make life easier.

func GetDaysInCurrentMonth added in v1.9.9

func GetDaysInCurrentMonth(now time.Time) int

GetDaysInCurrentMonth returns the number of days in the current month.

func GetFirstOfMonthDay added in v1.9.9

func GetFirstOfMonthDay(now time.Time) int64

func GetImageNameFromContainerInfo added in v1.9.9

func GetImageNameFromContainerInfo(imageName, containerName string) string

func GetInt32Pointer added in v1.9.9

func GetInt32Pointer(data int32) *int32

func GetJSONData

func GetJSONData(jsonValues map[string]interface{}) map[string]string

func GetJiraKeys

func GetJiraKeys(title string) (keys []string)

func GetMidnightTimestamp added in v1.9.9

func GetMidnightTimestamp(timestamp int64) int64

func GetPinyinFromChinese added in v1.9.9

func GetPinyinFromChinese(han string) (string, string)

func GetRandomNumString added in v1.2.0

func GetRandomNumString(length int) string

func GetRandomString added in v1.2.0

func GetRandomString(length int) string

func GetStrPointer added in v1.9.9

func GetStrPointer(data string) *string

func GetURLHostName

func GetURLHostName(urlAddr string) string

GetURLHostName ...

func Go added in v1.9.9

func Go(fn func())

func InStringArray added in v1.9.9

func InStringArray(target string, str_array []string) bool

func IsSameDay added in v1.9.9

func IsSameDay(timestamp1 int64, timestamp2 int64) bool

IsSameDay checks if two timestamps represent the same day.

func JSONToYaml

func JSONToYaml(json map[string]interface{}) (string, error)

func JoinYamls added in v1.9.9

func JoinYamls(files []string) string

func OverrideValues added in v1.9.9

func OverrideValues(currentValuesYaml, latestValuesYaml []byte, imageRelatedKey sets.String, onlyImages bool) ([]byte, error)

for keys exist in both yaml, current values will override the latest values

func ParseOwnerAndRepo added in v1.9.9

func ParseOwnerAndRepo(repoLink string, authType types.AuthType) (string, string)

ParseOwnerAndRepo extracts the owner and repo info from the given link, the link must have to following format: http(s)://example.com/owner/repo

func PathExists added in v1.9.9

func PathExists(path string) (bool, error)

func ReadFile added in v1.9.9

func ReadFile(filename string) ([]byte, error)

func ReadValuesYAML added in v1.9.9

func ReadValuesYAML(chartTree fs.FS, base string, logger *zap.SugaredLogger) ([]byte, error)

func ReadValuesYAMLFromLocal added in v1.9.9

func ReadValuesYAMLFromLocal(base string, logger *zap.SugaredLogger) ([]byte, error)

func RecursionGetKeyAndValue

func RecursionGetKeyAndValue(jsonValues map[string]interface{}, mapKey string)

RecursionGetKeyAndValue 递归获取map中的key和value

func RecursionReplaceValue

func RecursionReplaceValue(jsonValues map[string]interface{}, replaceKeyArr []string, replaceValue interface{})

RecursionReplaceValue 递归替换map中的value

func RemoveExtraSpaces added in v1.9.9

func RemoveExtraSpaces(input string) string

func ReplaceMapValue

func ReplaceMapValue(jsonValues map[string]interface{}, replaceMap map[string]interface{}) map[string]interface{}

ReplaceMapValue 拿匹配到的key和value去替换原始的map中的key和value

func ReplaceRepo

func ReplaceRepo(origin, addr, namespace string) string

func ReplaceTag added in v1.9.9

func ReplaceTag(origin, newTag string) string

func ReplaceWrapLine

func ReplaceWrapLine(script string) string

func ReturnValidLabelValue added in v1.9.9

func ReturnValidLabelValue(value string) string

value may only contain underscores or underscores

func SendRequest deprecated

func SendRequest(url, method string, header http.Header, body []byte) ([]byte, error)

Deprecated: do not use it any more, use http client in tool/httpclient instead.

func SplitManifests added in v1.3.0

func SplitManifests(content string) []string

func SplitYaml added in v1.9.9

func SplitYaml(yaml string) []string

func TrimURLScheme added in v1.8.0

func TrimURLScheme(urlAddr string) string

func UUID

func UUID() string

func WriteFile

func WriteFile(filename string, data []byte, perm os.FileMode) error

Types

type KVInput added in v1.9.9

type KVInput []*KeyValue

func (KVInput) FormYamlString added in v1.9.9

func (i KVInput) FormYamlString() (string, error)

type KeyValue added in v1.9.9

type KeyValue struct {
	Key   string      `json:"key"`
	Value interface{} `json:"value"`
}

TODO: the key field of this struct only support non-nested value e.g. the key "a.b" will not be parse as a nested value this is different from the behavior of our normal service KV parsing. How we handle the KV should be decided after further discussion.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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