utils

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

"github.com/orcaman/concurrent-map"

Index

Constants

View Source
const SHARD_COUNT = 32

Variables

This section is empty.

Functions

func DiffNano

func DiffNano(startTime time.Time) (diff int64)

DiffNano is return start & end time for program

func FileExist

func FileExist(path string) bool

FileExist return true if file exist

Types

type ConcurrentMap added in v1.1.0

type ConcurrentMap []*ConcurrentMapShared

A "thread" safe map of type string:Anything. To avoid lock bottlenecks this map is dived to several (len(m)) map shards.

func New added in v1.1.0

func New(shardCount ...int) ConcurrentMap

Creates a new concurrent map.

func (ConcurrentMap) Count added in v1.1.0

func (m ConcurrentMap) Count() int

Returns the number of elements within the map.

func (ConcurrentMap) Get added in v1.1.0

func (m ConcurrentMap) Get(key string) (interface{}, bool)

Retrieves an element from map under given key.

func (ConcurrentMap) GetShard added in v1.1.0

func (m ConcurrentMap) GetShard(key string) *ConcurrentMapShared

Returns shard under given key

func (*ConcurrentMap) Has added in v1.1.0

func (m *ConcurrentMap) Has(key string) bool

Looks up an item under specified key

func (*ConcurrentMap) IsEmpty added in v1.1.0

func (m *ConcurrentMap) IsEmpty() bool

Checks if map is empty.

func (ConcurrentMap) Items added in v1.1.0

func (m ConcurrentMap) Items() map[string]interface{}

Returns all items as map[string]interface{}

func (ConcurrentMap) Iter deprecated added in v1.1.0

func (m ConcurrentMap) Iter() <-chan Tuple

Returns an iterator which could be used in a for range loop.

Deprecated: using IterBuffered() will get a better performence

func (ConcurrentMap) IterBuffered added in v1.1.0

func (m ConcurrentMap) IterBuffered() <-chan Tuple

Returns a buffered iterator which could be used in a for range loop.

func (ConcurrentMap) Keys added in v1.1.0

func (m ConcurrentMap) Keys() []string

Return all keys as []string

func (ConcurrentMap) MSet added in v1.1.0

func (m ConcurrentMap) MSet(data map[string]interface{})

func (ConcurrentMap) MarshalJSON added in v1.1.0

func (m ConcurrentMap) MarshalJSON() ([]byte, error)

Reviles ConcurrentMap "private" variables to json marshal.

func (*ConcurrentMap) Remove added in v1.1.0

func (m *ConcurrentMap) Remove(key string)

Removes an element from the map.

func (*ConcurrentMap) Set added in v1.1.0

func (m *ConcurrentMap) Set(key string, value interface{})

Sets the given value under the specified key.

func (*ConcurrentMap) SetIfAbsent added in v1.1.0

func (m *ConcurrentMap) SetIfAbsent(key string, value interface{}) bool

Sets the given value under the specified key if no value was associated with it.

func (*ConcurrentMap) Upsert added in v1.1.0

func (m *ConcurrentMap) Upsert(key string, value interface{}, cb UpsertCb) (res interface{})

Insert or Update - updates existing element or inserts a new one using UpsertCb

type ConcurrentMapShared added in v1.1.0

type ConcurrentMapShared struct {
	sync.RWMutex // Read Write mutex, guards access to internal map.
	// contains filtered or unexported fields
}

A "thread" safe string to anything map.

type Curl

type Curl struct {
	Data map[string][]string
}

Curl store curl file use for go map struct

func NewCurl

func NewCurl(data string) (curl *Curl)

NewCurl is read string to Curl

func ParseTheFile

func ParseTheFile(path string) (curl *Curl, err error)

func ParseTheFileC

func ParseTheFileC(path string) (curls []*Curl, err error)

ParseTheFileC is read multi curl file to Curl struct

func (*Curl) GetBody

func (c *Curl) GetBody() (body string)

GetBody is get Body from Curl

func (*Curl) GetHeaders

func (c *Curl) GetHeaders() (headers ConcurrentMap)

GetHeaders is read Headers from Curl

func (*Curl) GetHeadersStr

func (c *Curl) GetHeadersStr() string

GetHeadersStr is get Header returns string

func (*Curl) GetMethod

func (c *Curl) GetMethod() (method string)

GetMethod is read Method from Curl

func (*Curl) GetUrl

func (c *Curl) GetUrl() (url string)

GetUrl is get url from Curl

type Tuple added in v1.1.0

type Tuple struct {
	Key string
	Val interface{}
}

Used by the Iter & IterBuffered functions to wrap two variables together over a channel,

type UpsertCb added in v1.1.0

type UpsertCb func(exist bool, valueInMap interface{}, newValue interface{}) interface{}

Callback to return new element to be inserted into the map It is called while lock is held, therefore it MUST NOT try to access other keys in same map, as it can lead to deadlock since Go sync.RWLock is not reentrant

Jump to

Keyboard shortcuts

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