util

package
v0.0.0-...-d5049b0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignString

func AssignString(values ...string) string

AssignString returns the first non-empty string It is equivalent the following in Javascript var value = val0 || val1 || val2 || default

func ComputeDelta

func ComputeDelta(last, current, defaultValue uint64) uint64

ComputeDelta computes positive delta between last and current integer value, returns a default if the delta is negative

func GetStdBucket

func GetStdBucket(key string) *stats.StandardDeviation

GetStdBucket gets the standard deviation bucket

func JoinString

func JoinString(strs ...string) string

JoinString joins multiple strings

func MinInt

func MinInt(a, b int) int

MinInt returns a smaller integer of two integers

func PreserveHeaderForRedirect

func PreserveHeaderForRedirect(req *http.Request, via []*http.Request) error

PreserveHeaderForRedirect preserves HTTP headers during HTTP redirect

func RandStringBytes

func RandStringBytes(n int) []byte

RandStringBytes generates n length byte array with each byte is randomly picked from lower or upper case letters

func ReadFile

func ReadFile(filename string) (osrelease map[string]string, err error)

ReadFile reads /etc/lsd_release Similar to Read(), but takes the name of a file to load instead

func ReceiverHeader

func ReceiverHeader(h *http.Header) (token, topicFN, pulsarURL string, err bool)

ReceiverHeader parses headers for Pulsar required configuration

func ReportError

func ReportError(err error) error

ReportError logs error

func ResponseErrorJSON

func ResponseErrorJSON(e error, w http.ResponseWriter, statusCode int)

ResponseErrorJSON builds a Http response.

func SingleSlashJoin

func SingleSlashJoin(a, b string) string

SingleSlashJoin joins two parts of url path with no double slash

func StrContains

func StrContains(strs []string, str string) bool

StrContains check if a string is contained in an array of string

func StrToInt

func StrToInt(str string, defaultNum int) int

StrToInt converts string to an integer format with a default if inproper value retrieved

func TimeDuration

func TimeDuration(configV, defaultV int, timeUnit time.Duration) time.Duration

TimeDuration evaluate the run interval with the guard default value

func TokenizeTopicFullName

func TokenizeTopicFullName(topicFn string) (isPersistent bool, tenant, namespace, topic string, err error)

TokenizeTopicFullName tokenizes a topic full name into persistent, tenant, namespace, and topic name.

func TopicFnToURL

func TopicFnToURL(topicFn string) (string, error)

TopicFnToURL converts fully qualified topic name to url route

func Trim

func Trim(str string) string

Trim trims leading/prefix and suffix spaces, tab, \n in a string

func VerifyMessageByPulsarConsumer

func VerifyMessageByPulsarConsumer(client pulsar.Client, topicName, expectedMessage string, completeChan chan *ConsumerResult) error

VerifyMessageByPulsarConsumer instantiates a Pulsar consumer and verifies an expected message

Types

type ConsumerResult

type ConsumerResult struct {
	Err             error
	InOrderDelivery bool
	Latency         time.Duration
	Timestamp       time.Time
}

ConsumerResult is Pulsar Consumer result for channel communication

type ResponseErr

type ResponseErr struct {
	Error string `json:"error"`
}

ResponseErr - Error struct for Http response

type SyncMap

type SyncMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

SyncMap is a generic map data structure protected with syc.RWMutex

func NewSycMap

func NewSycMap() *SyncMap

NewSycMap creates a new SyncMap

func (*SyncMap) Get

func (sm *SyncMap) Get(key interface{}) interface{}

Get returns the value to which the specified key is mapped, or nil if this map contains no mapping for the key.

func (*SyncMap) GetOrDefault

func (sm *SyncMap) GetOrDefault(key interface{}, defaultValue interface{}) interface{}

GetOrDefault returns the value to which the specified key is mapped, or nil if this map contains no mapping for the key.

func (*SyncMap) IsEmpty

func (sm *SyncMap) IsEmpty() bool

IsEmpty returns whether the map is empty

func (*SyncMap) Put

func (sm *SyncMap) Put(key interface{}, value interface{}) interface{}

Put associates the specified value with the specified key in this map

func (*SyncMap) Remove

func (sm *SyncMap) Remove(key interface{})

Remove removes the specified key and associsated value

func (*SyncMap) Replace

func (sm *SyncMap) Replace(key interface{}, value interface{}) interface{}

Replace puts a key and value pair and returns a previous value if exists,

func (*SyncMap) Size

func (sm *SyncMap) Size() int

Size returns the size of the map

Jump to

Keyboard shortcuts

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