utils

package
v0.1.48 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: Apache-2.0 Imports: 16 Imported by: 3

Documentation

Overview

Copyright 2018-2019 The logrange Authors

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolPtr

func BoolPtr(b bool) *bool

func BytesCopy

func BytesCopy(src []byte) []byte

BytesCopy makes a copy of src slice of bytes

func EscapeJsonStr

func EscapeJsonStr(s string) string

Slightly modified version of stringBytes() method from go's /src/encoding/json/encode.go Provides the same escaping/encoding except for the part that it does not escape HTML unsafe symbols and we don't care about jsonp as well...

func ExpandPaths

func ExpandPaths(paths []string) []string

ExpandPaths walks through provided paths and turn them to list of files. The input paths can, for instance, contain ["/var/log/*.log"], so the method will return list of files from the /var/log/ folder, which have .log extension.

func GetFileId

func GetFileId(file string, info os.FileInfo) string

GetFileId generates an id by file name and its info. The id can help to identify whether the file content was rewritten or not. For example, if two identifiers calculated for same file name are different, we assume the file content was rewritten between first and the second identifiers calculations. If the identifiers are same, we assume that new data could be added to the file, but previously written one stays unchanged.

func GetInt64Val

func GetInt64Val(ptr *int64, defVal int64) int64

GetInt64Val receives a pointer to int64 value and returns its value or defVal, if the pointer is nil

func GetIntVal

func GetIntVal(ptr *int, defVal int) int

GetIntVal receives a pointer to int value and returns its value or defVal, if the pointer is nil

func GetStringVal

func GetStringVal(ptr *string, defVal string) string

func GetUint64Val

func GetUint64Val(ptr *uint64, defVal uint64) uint64

GetUint64Val receives a pointer to uint64 value and returns its value or defVal, if the pointer is nil

func IntPtr

func IntPtr(i int) *int

func Md5

func Md5(s string) string

func NewNotifierOnIntTermSignal

func NewNotifierOnIntTermSignal(callback SignalCallbackFn)

func NextSimpleId

func NextSimpleId() uint64

NextSimpleId makes an pseudo-unique 64 bit identifier. The uniquiness could be supported by assigning the last 16 bits of the identifier unique per process. It is user's responsibility to be sure that the host Id part to be unique per process in a cluster of machines.

func ParseSimpleId added in v0.1.0

func ParseSimpleId(cid string) (uint64, error)

ParseSimpleId receives sid - string representation of an Id and tries to turn it to Id. Returns an error if the string cannot be decoded.

func PtrBool

func PtrBool(b *bool) (bool, bool)

returns (ptr value, ok), ok == false if ptr is nil

func PtrInt

func PtrInt(i *int) (int, bool)

returns (ptr value, ok), ok == false if ptr is nil

func RemoveDups

func RemoveDups(ss []string) []string

RemoveDups returns a slice where every element from ss meets only once

func SimpleId added in v0.1.0

func SimpleId(sid uint64) string

SimpleId turns sid to string

func Sleep

func Sleep(ctx context.Context, t time.Duration) bool

func ToJsonStr

func ToJsonStr(v interface{}) string

ToJsonStr encodes v to a json string. Don't use it in data streaming due to bad performance and memory allocations

func Wait

func Wait(ctx context.Context, ticker *time.Ticker) bool

func WaitDone

func WaitDone(done chan bool, t time.Duration) bool

func WaitWaitGroup

func WaitWaitGroup(wg *sync.WaitGroup, t time.Duration) bool

Types

type SignalCallbackFn

type SignalCallbackFn func(s os.Signal)

Directories

Path Synopsis
kvstring package contains functions for representing string key:value pairs as one string and converting such strings to maps etc.
kvstring package contains functions for representing string key:value pairs as one string and converting such strings to maps etc.

Jump to

Keyboard shortcuts

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