utils

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Display

func Display(data ...interface{})

Display print the data in console

func FileExists

func FileExists(name string) bool

FileExists reports whether the named file or directory exists.

func GetDisplayString

func GetDisplayString(data ...interface{}) string

GetDisplayString return data print string

func GetFuncName

func GetFuncName(i interface{}) string

GetFuncName get function name

func GetGOPATHs

func GetGOPATHs() []string

GetGOPATHs returns all paths in GOPATH variable.

func GrepFile

func GrepFile(patten string, filename string) (lines []string, err error)

GrepFile like command grep -E for example: GrepFile(`^hello`, "hello.txt") \n is striped while read

func InSlice

func InSlice(v string, sl []string) bool

InSlice checks given string in string slice or not.

func InSliceIface

func InSliceIface(v interface{}, sl []interface{}) bool

InSliceIface checks given interface in interface slice.

func PrintPointerInfo

func PrintPointerInfo(buf *bytes.Buffer, headlen int, pointers *pointerInfo)

PrintPointerInfo dump pointer value

func SearchFile

func SearchFile(filename string, paths ...string) (fullpath string, err error)

SearchFile Search a file in paths. this is often used in search config file in /etc ~/

func SelfDir

func SelfDir() string

SelfDir gets compiled executable file directory

func SelfPath

func SelfPath() string

SelfPath gets compiled executable file absolute path

func SliceChunk

func SliceChunk(slice []interface{}, size int) (chunkslice [][]interface{})

SliceChunk separates one slice to some sized slice.

func SliceDiff

func SliceDiff(slice1, slice2 []interface{}) (diffslice []interface{})

SliceDiff returns diff slice of slice1 - slice2.

func SliceFilter

func SliceFilter(slice []interface{}, a filtertype) (ftslice []interface{})

SliceFilter generates a new slice after filter function.

func SliceIntersect

func SliceIntersect(slice1, slice2 []interface{}) (diffslice []interface{})

SliceIntersect returns slice that are present in all the slice1 and slice2.

func SliceMerge

func SliceMerge(slice1, slice2 []interface{}) (c []interface{})

SliceMerge merges interface slices to one slice.

func SlicePad

func SlicePad(slice []interface{}, size int, val interface{}) []interface{}

SlicePad prepends size number of val into slice.

func SliceRand

func SliceRand(a []interface{}) (b interface{})

SliceRand returns random one from slice.

func SliceRandList

func SliceRandList(min, max int) []int

SliceRandList generate an int slice from min to max.

func SliceRange

func SliceRange(start, end, step int64) (intslice []int64)

SliceRange generates a new slice from begin to end with step duration of int64 number.

func SliceReduce

func SliceReduce(slice []interface{}, a reducetype) (dslice []interface{})

SliceReduce generates a new slice after parsing every value by reduce function

func SliceShuffle

func SliceShuffle(slice []interface{}) []interface{}

SliceShuffle shuffles a slice.

func SliceSum

func SliceSum(intslice []int64) (sum int64)

SliceSum sums all values in int64 slice.

func SliceUnique

func SliceUnique(slice []interface{}) (uniqueslice []interface{})

SliceUnique cleans repeated values in slice.

func Stack

func Stack(skip int, indent string) []byte

Stack get stack bytes

func ToShortTimeFormat

func ToShortTimeFormat(d time.Duration) string

short string format

Types

type BhojpurMap

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

BhojpurMap is a map with lock

func NewBhojpurMap

func NewBhojpurMap() *BhojpurMap

NewBhojpurMap return new safemap

func (*BhojpurMap) Check

func (m *BhojpurMap) Check(k interface{}) bool

Check Returns true if k is exist in the map.

func (*BhojpurMap) Count

func (m *BhojpurMap) Count() int

Count returns the number of items within the map.

func (*BhojpurMap) Delete

func (m *BhojpurMap) Delete(k interface{})

Delete the given key and value.

func (*BhojpurMap) Get

func (m *BhojpurMap) Get(k interface{}) interface{}

Get from maps return the k's value

func (*BhojpurMap) Items

func (m *BhojpurMap) Items() map[interface{}]interface{}

Items returns all items in safemap.

func (*BhojpurMap) Set

func (m *BhojpurMap) Set(k interface{}, v interface{}) bool

Set Maps the given key and value. Returns false if the key is already in the map and changes nothing.

type KV

type KV interface {
	GetKey() interface{}
	GetValue() interface{}
}

type KVs

type KVs interface {
	GetValueOr(key interface{}, defValue interface{}) interface{}
	Contains(key interface{}) bool
	IfContains(key interface{}, action func(value interface{})) KVs
}

KVs interface

func NewKVs

func NewKVs(kvs ...KV) KVs

NewKVs creates the *KVs instance

type SimpleKV

type SimpleKV struct {
	Key   interface{}
	Value interface{}
}

SimpleKV is common structure to store key-value pairs. When you need something like Pair, you can use this

func (*SimpleKV) GetKey

func (s *SimpleKV) GetKey() interface{}

func (*SimpleKV) GetValue

func (s *SimpleKV) GetValue() interface{}

type SimpleKVs

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

SimpleKVs will store SimpleKV collection as map

func (*SimpleKVs) Contains

func (kvs *SimpleKVs) Contains(key interface{}) bool

Contains checks if a key exists

func (*SimpleKVs) GetValueOr

func (kvs *SimpleKVs) GetValueOr(key interface{}, defValue interface{}) interface{}

GetValueOr returns the value for a given key, if non-existant it returns defValue

func (*SimpleKVs) IfContains

func (kvs *SimpleKVs) IfContains(key interface{}, action func(value interface{})) KVs

IfContains invokes the action on a key if it exists

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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