common

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InfoType  = "Info"
	ErrorType = "Error"
	AlertType = "Alert"
)
View Source
const HashLength = 32

Variables

View Source
var ZeroHash = [HashLength]byte{0}

Functions

func AccountAddressToEthAddr added in v0.0.4

func AccountAddressToEthAddr(addr string) (common.Address, error)

AccountAddressToEthAddr parses the given address to an ETH address.

func AccountAddressToHex

func AccountAddressToHex(addr string) (string, error)

func FormatJson

func FormatJson(msg interface{}) (string, error)

FormatJson returns the json-encoded of the given msg.

func FormatMDLink(msg string, link string) string

FormatMDLink creates a ref-text message following the MarkDown standard.

func MustAccountAddressToHex

func MustAccountAddressToHex(addr string) string

MustAccountAddressToHex is the same as AccountAddressToHex except that it will panic upon errors.

func MustFormatJson

func MustFormatJson(msg interface{}) string

MustFormatJson is the same as FormatJson, but it will panic if the given msg cannot be marshalled.

Types

type Cache added in v0.0.4

type Cache interface {
	SetDefault(string, interface{})
	Set(string, interface{}, time.Duration)
	Get(string) (interface{}, bool)
	GetTo(string, interface{}) error
	Remove(string)
	RemoveExpired()
}

Cache is a simple cache.

type Hash added in v0.0.4

type Hash [HashLength]byte

func Digest added in v0.0.4

func Digest(values ...interface{}) Hash

func MustNewHashFromString added in v0.0.4

func MustNewHashFromString(hexHash string) Hash

func NewHashFromString added in v0.0.4

func NewHashFromString(hexHash string) (Hash, error)

func RandomHash added in v0.0.4

func RandomHash() Hash

func (Hash) Bytes added in v0.0.4

func (h Hash) Bytes() []byte

func (Hash) IsZero added in v0.0.4

func (h Hash) IsZero() bool

func (Hash) String added in v0.0.4

func (h Hash) String() string

type SimpleCache added in v0.0.4

type SimpleCache struct {
	*cache.Cache
}

func NewSimpleCache added in v0.0.4

func NewSimpleCache() *SimpleCache

NewSimpleCache creates a new SimpleCache with default expiration and cleanUpInterval.

func (*SimpleCache) Get added in v0.0.4

func (c *SimpleCache) Get(k string) (interface{}, bool)

func (*SimpleCache) GetTo added in v0.0.4

func (c *SimpleCache) GetTo(k string, ret interface{}) error

func (*SimpleCache) Remove added in v0.0.4

func (c *SimpleCache) Remove(k string)

func (*SimpleCache) RemoveExpired added in v0.0.4

func (c *SimpleCache) RemoveExpired()

func (*SimpleCache) Set added in v0.0.4

func (c *SimpleCache) Set(k string, v interface{}, expired time.Duration)

func (*SimpleCache) SetDefault added in v0.0.4

func (c *SimpleCache) SetDefault(k string, v interface{})

Jump to

Keyboard shortcuts

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