utils

package
v0.22.23 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: Apache-2.0 Imports: 9 Imported by: 5

Documentation

Overview

Package utils is the utilities to process internal data of sdk

Index

Constants

This section is empty.

Variables

View Source
var FrequencePatcher = NewRegexpPatcher(`"Frequence":\s?"([\d.]+)"`, `"Frequence": $1`)

FrequencePatcher will convert `Frequence` as float64

View Source
var PortPatcher = NewRegexpPatcher(`"Port":\s?"(\d+)"`, `"Port": $1`)

PortPatcher will convert `Port` as integer

View Source
var RetCodePatcher = NewRegexpPatcher(`"RetCode":\s?"(\d+)"`, `"RetCode": $1`)

RetCodePatcher will convert `RetCode` as integer

Functions

func CheckStringIn

func CheckStringIn(val string, availables []string) error

CheckStringIn will check if the value is contains by an array

func IsStringIn

func IsStringIn(val string, availables []string) bool

IsStringIn will return if the value is contains by an array

func MergeMap

func MergeMap(args ...map[string]string) map[string]string

MergeMap will merge two map and return a new map

func SetMapIfNotExists

func SetMapIfNotExists(m map[string]string, k string, v string)

SetMapIfNotExists will set a key-value of the map if the key is not exists

func ValueAtPath

func ValueAtPath(v interface{}, path string) (interface{}, error)

ValueAtPath will get struct attribute value by recursive

Types

type FuncWaiter

type FuncWaiter struct {
	Interval    time.Duration
	MaxAttempts int
	Checker     func() (bool, error)
	IgnoreError bool
	// contains filtered or unexported fields
}

FuncWaiter used for waiting any condition function.

func (*FuncWaiter) Cancel

func (w *FuncWaiter) Cancel() error

Cancel will stop all of WaitForCompletion function call.

func (*FuncWaiter) WaitForCompletion

func (w *FuncWaiter) WaitForCompletion() error

WaitForCompletion will wait until the state of consdition is available. It will call the condition function to ensure state with interval.

type Patch

type Patch interface {
	Patch([]byte) []byte
}

Patch is the patch object to provider a converter function

type RegexpPatcher

type RegexpPatcher struct {
	// contains filtered or unexported fields
}

RegexpPatcher a patch object to provider a converter function from regular expression

func NewRegexpPatcher

func NewRegexpPatcher(regex string, repl string) *RegexpPatcher

NewRegexpPatcher will return a patch object to provider a converter function from regular expression

func (*RegexpPatcher) Patch

func (p *RegexpPatcher) Patch(body []byte) []byte

Patch will convert a bytes to another bytes with patch rules

func (*RegexpPatcher) PatchString added in v0.6.7

func (p *RegexpPatcher) PatchString(body string) string

PatchString will convert a string to another string with patch rules

type Waiter

type Waiter interface {
	WaitForCompletion() error
	Cancel() error
}

Waiter to wait sth until it completed.

Jump to

Keyboard shortcuts

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