common

package
v0.0.0-...-7ece11e Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 40 Imported by: 25

Documentation

Index

Constants

View Source
const (
	EmptyString       = ""
	ZeroByte          = byte(0x00)
	DateOutputFormat  = "2006-01-02T15:04:05.999999"
	BigIntSize        = 32 // bytes
	CheckSumLen       = 4  // bytes
	AESKeySize        = 32 // bytes
	Int32Size         = 4  // bytes
	Uint32Size        = 4  // bytes
	Uint64Size        = 8  // bytes
	HashSize          = 32 // bytes
	MaxHashStringSize = HashSize * 2
	Base58Version     = 0
)

for common

View Source
const (
	// for key size
	PrivateKeySize      = 32  // bytes
	PublicKeySize       = 32  // bytes
	BLSPublicKeySize    = 128 // bytes
	BriPublicKeySize    = 33  // bytes
	TransmissionKeySize = 32  //bytes
	ReceivingKeySize    = 32  // bytes
	PaymentAddressSize  = 64  // bytes
	// for signature size
	// it is used for both privacy and no privacy
	SigPubKeySize    = 32
	SigNoPrivacySize = 64
	SigPrivacySize   = 96
	IncPubKeyB58Size = 51

	MaxPSMsgSize = 1 << 23 //4Mb
)

size data for incognito key and signature

View Source
const (
	TxNormalType          = "n"   // normal tx(send and receive coin)
	TxRewardType          = "s"   // reward tx
	TxReturnStakingType   = "rs"  //
	TxConversionType      = "cv"  // Convert 1 - 2 normal tx
	TxTokenConversionType = "tcv" // Convert 1 - 2 token tx
	//TxCustomTokenType        = "t"  // token  tx with no supporting privacy
	TxCustomTokenPrivacyType = "tp" // token  tx with supporting privacy
)

For all Transaction information

View Source
const (
	TxActTranfer = iota // Tx for tranfer PRV/Token
	TxActBurning        // Tx burn PRV/Token
	TxActInit           // Tx init PRV/Token
)
View Source
const (
	BeaconRole    = "beacon"
	ShardRole     = "shard"
	CommitteeRole = "committee"
	PendingRole   = "pending"
	SyncingRole   = "syncing" //this is for shard case - when beacon tell it is committee, but its state not
	WaitingRole   = "waiting"

	BlsConsensus    = "bls"
	BridgeConsensus = "dsa"
	IncKeyType      = "inc"
)

CONSENSUS

View Source
const (
	BeaconChainKey = "beacon"
	ShardChainKey  = "shard"
)
View Source
const (
	BeaconChainID                = -1
	BeaconChainSyncID            = 255
	BeaconChainDatabaseDirectory = "beacon"
	ShardChainDatabaseDirectory  = "shard"
)
View Source
const (
	SHARD_STAKING_AMOUNT      = 1750 * 1e9
	BEACON_MIN_STAKING_AMOUNT = 87500 * 1e9
)
View Source
const (
	REPLACE_IN  = 0
	REPLACE_OUT = 1
)
View Source
const (
	AbiJson                   = `` /* 13014-byte string literal not displayed */
	BridgeShardID             = 1
	EthAddrStr                = "0x0000000000000000000000000000000000000000"
	NativeToken               = "0x0000000000000000000000000000000000000000"
	BSCPrefix                 = "BSC"
	PLGPrefix                 = "PLG"
	FTMPrefix                 = "FTM"
	AURORAPrefix              = "AUR"
	AVAXPrefix                = "AVX"
	ExternalBridgeTokenLength = 20
	EVMAddressLength          = 40
	UnifiedTokenPrefix        = "UT"
	NEARPrefix                = "NER"
)

Ethereum Decentralized bridge

View Source
const (
	BridgeRequestNotFoundStatus   = 0
	BridgeRequestProcessingStatus = 1
	BridgeRequestAcceptedStatus   = 2
	BridgeRequestRejectedStatus   = 3

	PDENotFoundStatus = 0

	PDEContributionWaitingStatus          = 1
	PDEContributionAcceptedStatus         = 2
	PDEContributionRefundStatus           = 3
	PDEContributionMatchedNReturnedStatus = 4

	PDETradeAcceptedStatus = 1
	PDETradeRefundStatus   = 2

	PDECrossPoolTradeAcceptedStatus = 1
	PDECrossPoolTradeRefundStatus   = 2

	PDEWithdrawalAcceptedStatus = 1
	PDEWithdrawalRejectedStatus = 2

	PDEFeeWithdrawalAcceptedStatus = 1
	PDEFeeWithdrawalRejectedStatus = 2

	MinTxFeesOnTokenRequirement                             = 10000000000000 // 10000 prv, this requirement is applied from beacon height 87301 mainnet
	BeaconBlockHeighMilestoneForMinTxFeesOnTokenRequirement = 87301          // milestone of beacon height, when apply min fee on token requirement
)

Bridge, PDE & Portal statuses for RPCs

View Source
const (
	PDEContributionWaitingChainStatus          = "waiting"
	PDEContributionMatchedChainStatus          = "matched"
	PDEContributionRefundChainStatus           = "refund"
	PDEContributionMatchedNReturnedChainStatus = "matchedNReturned"

	PDETradeAcceptedChainStatus = "accepted"
	PDETradeRefundChainStatus   = "refund"

	PDEWithdrawalAcceptedChainStatus = "accepted"
	PDEWithdrawalRejectedChainStatus = "rejected"

	PDEFeeWithdrawalAcceptedChainStatus = "accepted"
	PDEFeeWithdrawalRejectedChainStatus = "rejected"

	PDEWithdrawalOnFeeAcceptedChainStatus      = "onFeeAccepted"
	PDEWithdrawalOnPoolPairAcceptedChainStatus = "onPoolPairAccepted"
	PDEWithdrawalWithPRVFeeRejectedChainStatus = "withPRVFeeRejected"

	PDECrossPoolTradeFeeRefundChainStatus          = "xPoolTradeRefundFee"
	PDECrossPoolTradeSellingTokenRefundChainStatus = "xPoolTradeRefundSellingToken"
	PDECrossPoolTradeAcceptedChainStatus           = "xPoolTradeAccepted"
)

PDE statuses for chain

View Source
const (
	Pdexv3RejectUserMintNftStatus = "rejected"
	Pdexv3AcceptUserMintNftStatus = "accept"
	Pdexv3RejectStakingStatus     = "rejected"
	Pdexv3AcceptStakingStatus     = "accept"
	Pdexv3RejectUnstakingStatus   = "rejected"
	Pdexv3AcceptUnstakingStatus   = "accept"

	Pdexv3AcceptStatus = byte(1)
	Pdexv3RejectStatus = byte(2)
)
View Source
const (
	RejectedStatusStr  = "rejected"
	AcceptedStatusStr  = "accepted"
	WaitingStatusStr   = "waiting"
	FilledStatusStr    = "filled"
	RejectedStatusByte = byte(0)
	AcceptedStatusByte = byte(1)
	WaitingStatusByte  = byte(2)
	FilledStatusByte   = byte(3)
)
View Source
const (
	BurningAddress  = "15pABFiJVeh9D5uiQEhQX4SVibGGbdAVipQxBdxkmDqAJaoG1EdFKHBrNfs"
	BurningAddress2 = "12RxahVABnAVCGP3LGwCn8jkQxgw7z1x14wztHzn455TTVpi1wBq9YGwkRMQg3J4e657AbAnCvYCJSdA9czBUNuCKwGSRQt55Xwz8WA"
)

burning addresses

View Source
const (
	PortalRelayingFlag = "PortalRelaying"
	PortalV3Flag       = "PortalV3"
	PortalV4Flag       = "PortalV4"
)

================ Feature Flags ================

View Source
const (
	PortalVersion3 = 3
	PortalVersion4 = 4
)
View Source
const (
	DefaultNetworkID = iota
	ETHNetworkID
	BSCNetworkID
	PLGNetworkID
	FTMNetworkID
	AURORANetworkID
	AVAXNetworkID
	NEARNetworkID
)

Add to the end of the list. DO NOT edit the order

View Source
const (
	SubOperator = 0
	AddOperator = 1
)
View Source
const (
	UnexpectedErr = iota
	Base58CheckDecodeErr
)
View Source
const (
	// Llongfile modifies the logger output to include full path and line number
	// of the logging callsite, e.g. /a/b/c/main.go:123.
	Llongfile uint32 = 1 << iota

	// Lshortfile modifies the logger output to include filename and line number
	// of the logging callsite, e.g. main.go:123.  Overrides Llongfile.
	Lshortfile
)

Flags to modify Backend's behavior.

View Source
const ETHChainName = "eth"
View Source
const (
	EVMNetworkType = iota
)
View Source
const (
	HexEmptyRoot = "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
)
View Source
const (
	MaxTxRequestIssue = 400
)
View Source
const PDEXDenominatingDecimal = 9
View Source
const PDEXIDStr = "0000000000000000000000000000000000000000000000000000000000000006"
View Source
const PRVIDStr = "0000000000000000000000000000000000000000000000000000000000000004"
View Source
const (
	SALARY_VER_FIX_HASH = 1
)

Variables

View Source
var (
	MaxTxSize    = uint64(500)  // unit KB = 500KB
	MaxBlockSize = uint64(2000) //unit kilobytes = 2 Megabyte
)
View Source
var (
	PRVCoinID             = Hash{4} // To send PRV in custom token
	PRVCoinName           = "PRV"   // To send PRV in custom token
	ConfidentialAssetID   = Hash{5}
	ConfidentialAssetName = "CA"
	PDEXCoinID            = Hash{6}
	PDEXCoinName          = "PDEX"
	MaxShardNumber        = 0
)

special token ids (aka. PropertyID in custom token)

View Source
var (
	BurningAddressByte  []byte
	BurningAddressByte2 []byte
)
View Source
var (
	FgGreen   = color.New(color.FgGreen).FprintfFunc()
	FgRed     = color.New(color.FgRed).FprintfFunc()
	FgYellow  = color.New(color.FgYellow).FprintfFunc()
	FgBlue    = color.New(color.FgBlue).FprintfFunc()
	FgCyan    = color.New(color.FgCyan).FprintfFunc()
	FgMagenta = color.New(color.FgMagenta).FprintfFunc()
	FgWhite   = color.New(color.FgWhite).FprintfFunc()
)
View Source
var CipherTextIsEmptyErr = errors.New("ciphertext is empty")
View Source
var ElasticLogService *aggregatelog.LogService
View Source
var (
	EmptyRoot = HexToHash(HexEmptyRoot)
)
View Source
var ErrCodeMessage = map[int]struct {
	code    int
	message string
}{
	UnexpectedErr:        {-10001, "Unexpected error"},
	Base58CheckDecodeErr: {-10002, "Unexpected error"},
}
View Source
var InvalidAESKeyErr = errors.New("aes key is invalid")
View Source
var InvalidHashSizeErr = errors.New("invalid hash size")
View Source
var InvalidMaxHashSizeErr = errors.New("invalid max hash size")
View Source
var NilHashErr = errors.New("input hash is nil")
View Source
var PlainTextIsEmptyErr = errors.New("plaintext is empty")
View Source
var SentryLogService *aggregatelog.LogService
View Source
var TIMESLOT = uint64(0) //need to be set when init chain

Functions

func Add0xPrefix

func Add0xPrefix(str string) string

Add0xPrefix adds 0x prefix (if there) from string

func AddPaddingBigInt

func AddPaddingBigInt(numInt *big.Int, fixedSize int) []byte

AddPaddingBigInt adds padding to big int to it is fixed size and returns bytes array

func AggregationLogInit

func AggregationLogInit()

func AppDataDir

func AppDataDir(appName string, roaming bool) string

AppDataDir returns an operating system specific directory to be used for storing application data for an application.

The appName parameter is the name of the application the data directory is being requested for. This function will prepend a period to the appName for POSIX style operating systems since that is standard practice. An empty appName or one with a single dot is treated as requesting the current directory so only "." will be returned. Further, the first character of appName will be made lowercase for POSIX style operating systems and uppercase for Mac and Windows since that is standard practice.

The roaming parameter only applies to Windows where it specifies the roaming application data profile (%APPDATA%) should be used instead of the local one (%LOCALAPPDATA%) that is used by default.

Example results:

dir := AppDataDir("myapp", false)
 POSIX (Linux/BSD): ~/.myapp
 Mac OS: $HOME/Library/Application Support/Myapp
 Windows: %LOCALAPPDATA%\Myapp
 Plan 9: $home/myapp

func AppendSliceString

func AppendSliceString(arrayStrings ...[][]string) [][]string

AppendSliceString is a variadic function, receives some lists of array of strings and appends them to one list of array of strings

func AssertAndConvertNumber

func AssertAndConvertNumber(numInt interface{}) (uint64, error)

AssertAndConvertStrToNumber asserts and convert a passed input to uint64 number

func AssertAndConvertStrToNumber

func AssertAndConvertStrToNumber(numStr interface{}) (uint64, error)

AssertAndConvertStrToNumber asserts and convert a passed input to uint64 number

func BoolToByte

func BoolToByte(value bool) byte

BoolToByte receives a value in bool and returns a value in byte

func BytesSToUint16

func BytesSToUint16(b []byte) (uint16, error)

func BytesToInt

func BytesToInt(bytesArr []byte) int

BytesToInt reverts an integer number from 2-byte array

func BytesToInt32

func BytesToInt32(b []byte) (int32, error)

BytesToInt32 converts little endian 4-byte array to int32 number

func BytesToInt64

func BytesToInt64(bytesArr []byte) int64

BytesToInt reverts an integer number from 2-byte array

func BytesToUint16

func BytesToUint16(b [2]byte) uint16

func BytesToUint32

func BytesToUint32(b []byte) (uint32, error)

BytesToUint32 converts big endian 4-byte array to uint32 number

func BytesToUint64

func BytesToUint64(b []byte) (uint64, error)

BytesToUint64 converts little endian 8-byte array to uint64 number

func CheckError

func CheckError(errs ...error) error

CheckError receives a list of errors returns the first error which is not nil

func CleanAndExpandPath

func CleanAndExpandPath(path string, defaultHomeDir string) string

cleanAndExpandPath expands environment variables and leading ~ in the passed path, cleans the result, and returns it.

func CompareStringArray

func CompareStringArray(src []string, dst []string) bool

CompareStringArray receives 2 arrays of string and check whether 2 arrays is the same or not

func CompressDatabase

func CompressDatabase(src string, dst string) error

func CopyBytes

func CopyBytes(b []byte) (copiedBytes []byte)

CopyBytes returns an exact copy of the provided bytes.

func DecodeETHAddr

func DecodeETHAddr(addr string) ([]byte, error)

DecodeETHAddr converts address string (not contain 0x prefix) to 32 bytes slice

func DecompressDatabaseBackup

func DecompressDatabaseBackup(src string, dst string) error

func DeepCopyString

func DeepCopyString(src []string) []string

func FileExists

func FileExists(name string) bool

FilesExists reports whether the named file or directory exists.

func FromHex

func FromHex(s string) []byte

FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".

func GZipFromBytes

func GZipFromBytes(src []byte) ([]byte, error)

GZipFromBytes receives bytes array and compresses that bytes array using gzip

func GZipToBytes

func GZipToBytes(src []byte) ([]byte, error)

GZipToBytes receives bytes array which is compressed data using gzip returns decompressed bytes array

func GetCPUSample

func GetCPUSample() (idle, total uint64)

func GetEpochFromBeaconHeight

func GetEpochFromBeaconHeight(beaconHeight uint64, epochNumBlocksPerEpoch uint64) uint64

func GetShardChainKey

func GetShardChainKey(shardID byte) string

func GetShardIDFromLastByte

func GetShardIDFromLastByte(b byte) byte

GetShardIDFromLastByte receives a last byte of public key and returns a corresponding shardID

func GetValidStaker

func GetValidStaker(committees []string, stakers []string) []string

func HandleCaptureMessage

func HandleCaptureMessage(message, level string) error

func Has0xPrefix

func Has0xPrefix(str string) bool

Has0xPrefix validates str begins with '0x' or '0X'.

func HashB

func HashB(b []byte) []byte

HashB calculates SHA3-256 hashing of input b and returns the result in bytes array.

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func IndexOfByte

func IndexOfByte(item byte, array []byte) int

IndexOfByte receives a array of bytes and a item byte It checks whether a item is contained in array or not and returns the first index of the item in the array It returns -1 if the item is not in the array

func IndexOfHash

func IndexOfHash(item Hash, list []Hash) int

func IndexOfInt

func IndexOfInt(target int, arr []int) int

func IndexOfStr

func IndexOfStr(item string, list []string) int

IndexOfStr receives a list of strings and a item string It checks whether a item is contained in list or not and returns the first index of the item in the list It returns -1 if the item is not in the list

func IndexOfStrInHashMap

func IndexOfStrInHashMap(v string, m map[Hash]string) int

IndexOfStrInHashMap receives a map[Hash]string and a value string It checks whether a value is contained in map or not It returns -1 if the item is not in the list and return 1 otherwise

func IndexOfUint64

func IndexOfUint64(target uint64, arr []uint64) int

func Int32ToBytes

func Int32ToBytes(value int32) []byte

Int32ToBytes converts int32 number to little endian 4-byte array

func Int64ToBytes

func Int64ToBytes(value int64) []byte

Int64ToBytes converts int64 number to little endian 8-byte array

func IntToBytes

func IntToBytes(n int) []byte

IntToBytes converts an integer number to 2-byte array in big endian

func InterfaceSlice

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

InterfaceSlice receives a slice which is a interface and converts it into slice of interface

func IsPublicKeyBurningAddress

func IsPublicKeyBurningAddress(publicKey []byte) bool

func RandBigIntMaxRange

func RandBigIntMaxRange(max *big.Int) (*big.Int, error)

RandBigIntMaxRange generates a big int with maximum value

func RandBytes

func RandBytes(length int) []byte

RandBytes generates random bytes with length

func RandInt

func RandInt() int

RandInt returns a random int number using math/rand

func RandInt64

func RandInt64() int64

RandInt64 returns a random int64 number using math/rand

func RandIntInterval

func RandIntInterval(L, R int) int

RandIntInterval returns a random int in range [L; R]

func RandUint64

func RandUint64() uint64

func Remove0xPrefix

func Remove0xPrefix(str string) string

Remove0xPrefix removes 0x prefix (if there) from string

func Render

func Render(data []byte) string

func SHA256

func SHA256(b []byte) []byte

SHA256 calculates SHA256-256 hashing of input b and returns the result in bytes array.

func SliceExists

func SliceExists(slice interface{}, item interface{}) (bool, error)

SliceExists receives a slice and a item in interface type checks whether the slice contain the item or not

func TokenHashToString

func TokenHashToString(h *Hash) string

func Uint16ToBytes

func Uint16ToBytes(v uint16) [2]byte

func Uint32ToBytes

func Uint32ToBytes(value uint32) []byte

Uint32ToBytes converts uint32 number to big endian 4-byte array

func Uint64ToBytes

func Uint64ToBytes(value uint64) []byte

Uint64ToBytes converts uint64 number to little endian 8-byte array

Types

type AES

type AES struct {
	Key []byte
}

func (*AES) Decrypt

func (aesObj *AES) Decrypt(ciphertext []byte) ([]byte, error)

func (*AES) Encrypt

func (aesObj *AES) Encrypt(plaintext []byte) ([]byte, error)

type Backend

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

Backend is a logging backend. Subsystems created from the backend write to the backend's Writer. Backend provides atomic writes to the Writer from all subsystems.

func NewBackend

func NewBackend(w io.Writer, opts ...BackendOption) *Backend

NewBackend creates a logger backend from a Writer.

func (*Backend) Logger

func (b *Backend) Logger(subsystemTag string, disable bool) Logger

Logger returns a new logger for a particular subsystem that writes to the Backend b. A tag describes the subsystem and is included in all log messages. The logger uses the info verbosity level by default.

type BackendOption

type BackendOption func(b *Backend)

BackendOption is a function used to modify the behavior of a Backend.

func WithFlags

func WithFlags(flags uint32) BackendOption

WithFlags configures a Backend to use the specified flags rather than using the package's defaults as determined through the LOGFLAGS environment variable.

type ChainInterface

type ChainInterface interface {
	GetShardID() int
}

type ErrorSaver

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

func (*ErrorSaver) Get

func (s *ErrorSaver) Get() error

func (*ErrorSaver) Save

func (s *ErrorSaver) Save(errs ...error) error

type Hash

type Hash [HashSize]byte

func BytesToHash

func BytesToHash(b []byte) Hash

func GenerateHashFromMapByteString

func GenerateHashFromMapByteString(maps1 map[byte][]string) (Hash, error)

func GenerateHashFromMapStringBool

func GenerateHashFromMapStringBool(maps1 map[string]bool) (Hash, error)

func GenerateHashFromMapStringString

func GenerateHashFromMapStringString(maps1 map[string]string) (Hash, error)

func GenerateHashFromStringArray

func GenerateHashFromStringArray(strs []string) (Hash, error)

func GenerateHashFromTwoMapByteString

func GenerateHashFromTwoMapByteString(maps1 map[byte][]string, maps2 map[byte][]string) (Hash, error)

func GenerateZeroValueHash

func GenerateZeroValueHash() (Hash, error)

func HashArrayInterface

func HashArrayInterface(target interface{}) (Hash, error)

func HashArrayOfHashArray

func HashArrayOfHashArray(target []Hash) Hash

func HashH

func HashH(b []byte) Hash

HashB calculates SHA3-256 hashing of input b and returns the result in Hash.

func HexToHash

func HexToHash(s string) Hash

HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func Keccak256

func Keccak256(data ...[]byte) Hash

Keccak256 returns Keccak256 hash as a Hash object for storing and comparing

func Keccak256Hash

func Keccak256Hash(data ...[]byte) (h Hash)

Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.

func TokenStringToHash

func TokenStringToHash(s string) (*Hash, error)

func (Hash) Bytes

func (h Hash) Bytes() []byte

func (*Hash) Cmp

func (hashObj *Hash) Cmp(target *Hash) (int, error)

Cmp compare two hashes hash = target : return 0 hash > target : return 1 hash < target : return -1

func (*Hash) Decode

func (hashObj *Hash) Decode(dst *Hash, src string) error

Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a destination.

func (*Hash) Format

func (hashObj *Hash) Format(f fmt.State, c rune)

Format writes first few bytes of hash for debugging

func (*Hash) GetBytes

func (hashObj *Hash) GetBytes() []byte

GetBytes returns bytes array of hashObj

func (*Hash) IsEqual

func (hashObj *Hash) IsEqual(target *Hash) bool

IsEqual returns true if target is the same as hashObj.

func (Hash) IsZeroValue

func (h Hash) IsZeroValue() bool

func (Hash) MarshalText

func (hashObj Hash) MarshalText() ([]byte, error)

MarshalText converts hashObj string to bytes array

func (Hash) NewHash

func (hashObj Hash) NewHash(newHash []byte) (*Hash, error)

NewHash receives a bytes array and returns a corresponding object Hash

func (*Hash) NewHash2

func (hashObj *Hash) NewHash2(newHash []byte) Hash

NewHash receives a bytes array and returns a corresponding object Hash

func (Hash) NewHashFromStr

func (hashObj Hash) NewHashFromStr(hash string) (*Hash, error)

NewHashFromStr creates a Hash from a hash string. The string should be the hexadecimal string of a byte-reversed hash, but any missing characters result in zero padding at the end of the Hash.

func (Hash) NewHashFromStr2

func (hashObj Hash) NewHashFromStr2(hash string) Hash

NewHashFromStr2 creates a Hash from a hash string. The string should be the hexadecimal string of a byte-reversed hash, but any missing characters result in zero padding at the end of the Hash.

func (*Hash) SetBytes

func (hashObj *Hash) SetBytes(newHash []byte) error

SetBytes sets the bytes array which represent the hash.

func (Hash) String

func (hashObj Hash) String() string

String returns the Hash as the hexadecimal string of the byte-reversed hash.

func (*Hash) UnmarshalJSON

func (hashObj *Hash) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal json data to hashObj

func (Hash) UnmarshalText

func (hashObj Hash) UnmarshalText(text []byte) error

UnmarshalText reverts bytes array to hashObj

type Level

type Level uint32

Level is the level at which a logger is configured. All messages sent to a level which is below the current level are filtered.

const (
	LevelTrace Level = iota
	LevelDebug
	LevelInfo
	LevelWarn
	LevelError
	LevelCritical
	LevelOff
)

Level constants.

func LevelFromString

func LevelFromString(s string) (l Level, ok bool)

LevelFromString returns a level based on the input string s. If the input can't be interpreted as a valid log level, the info level and false is returned.

func (Level) String

func (l Level) String() string

String returns the tag of the logger used in log messages, or "OFF" if the level will not produce any log output.

type Logger

type Logger interface {
	// Tracef formats message according to format specifier and writes to
	// to log with LevelTrace.
	Tracef(format string, params ...interface{})

	// Debugf formats message according to format specifier and writes to
	// log with LevelDebug.
	Debugf(format string, params ...interface{})

	// Infof formats message according to format specifier and writes to
	// log with LevelInfo.
	Infof(format string, params ...interface{})

	// Warnf formats message according to format specifier and writes to
	// to log with LevelWarn.
	Warnf(format string, params ...interface{})

	// Errorf formats message according to format specifier and writes to
	// to log with LevelError.
	Errorf(format string, params ...interface{})

	// Criticalf formats message according to format specifier and writes to
	// log with LevelCritical.
	Criticalf(format string, params ...interface{})

	// Trace formats message using the default formats for its operands
	// and writes to log with LevelTrace.
	Trace(v ...interface{})

	// Debug formats message using the default formats for its operands
	// and writes to log with LevelDebug.
	Debug(v ...interface{})

	// Info formats message using the default formats for its operands
	// and writes to log with LevelInfo.
	Info(v ...interface{})

	// Warn formats message using the default formats for its operands
	// and writes to log with LevelWarn.
	Warn(v ...interface{})

	// Error formats message using the default formats for its operands
	// and writes to log with LevelError.
	Error(v ...interface{})

	// Critical formats message using the default formats for its operands
	// and writes to log with LevelCritical.
	Critical(v ...interface{})

	// Level returns the current logging level.
	Level() Level

	// SetLevel changes the logging level to the passed level.
	SetLevel(level Level)
}

Logger is an interface which describes a level-based logger. A default implementation of Logger is implemented by this package and can be created by calling (*Backend).Logger.

var Disabled Logger

Disabled is a Logger that will never output anything.

type MapStringBool

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

func NewMapStringBool

func NewMapStringBool() *MapStringBool

func (*MapStringBool) GenerateHash

func (s *MapStringBool) GenerateHash() (Hash, error)

func (*MapStringBool) Get

func (s *MapStringBool) Get(k string) (bool, bool)

func (*MapStringBool) GetMap

func (s *MapStringBool) GetMap() map[string]bool

func (*MapStringBool) LazyCopy

func (s *MapStringBool) LazyCopy() *MapStringBool

func (*MapStringBool) Remove

func (s *MapStringBool) Remove(k string)

func (*MapStringBool) Set

func (s *MapStringBool) Set(k string, v bool)

type MapStringString

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

MapStringString ...

func NewMapStringString

func NewMapStringString() *MapStringString

NewMapStringString ...

func (*MapStringString) Data

func (s *MapStringString) Data() map[string]string

func (*MapStringString) GenerateHash

func (s *MapStringString) GenerateHash() (Hash, error)

GenerateHash ...

func (*MapStringString) Get

func (s *MapStringString) Get(k string) (string, bool)

Get ...

func (*MapStringString) GetMap

func (s *MapStringString) GetMap() map[string]string

GetMap ...

func (*MapStringString) LazyCopy

func (s *MapStringString) LazyCopy() *MapStringString

LazyCopy ...

func (*MapStringString) Remove

func (s *MapStringString) Remove(k string)

Remove ...

func (*MapStringString) Set

func (s *MapStringString) Set(k string, v string)

Set ...

func (*MapStringString) SetData

func (s *MapStringString) SetData(data map[string]string)

func (*MapStringString) SetHash

func (s *MapStringString) SetHash(hash *Hash)

func (*MapStringString) SetUpdated

func (s *MapStringString) SetUpdated(updated bool)

type SimpleAddr

type SimpleAddr struct {
	Net, Addr string
}

SimpleAddr implements the net.Addr interface with two fields struct

func ParseListener

func ParseListener(addr string, netType string) (*SimpleAddr, error)

ParseListener determines whether the listen address is IPv4 and IPv6 and returns a slice of appropriate net.Addrs to listen on with TCP. It also properly detects address which apply to "all interfaces" and adds the address as both IPv4 and IPv6.

func ParseListeners

func ParseListeners(addrs []string, netType string) ([]SimpleAddr, error)

ParseListeners determines whether each listen address is IPv4 and IPv6 and returns a slice of appropriate net.Addrs to listen on with TCP. It also properly detects addresses which apply to "all interfaces" and adds the address as both IPv4 and IPv6.

func (SimpleAddr) Network

func (a SimpleAddr) Network() string

Network returns the network. This is part of the net.Addr interface.

func (SimpleAddr) String

func (a SimpleAddr) String() string

String returns the address. This is part of the net.Addr interface.

type StorageSize

type StorageSize float64

StorageSize is a wrapper around a float value that supports user friendly formatting.

func (StorageSize) String

func (s StorageSize) String() string

String implements the stringer interface.

func (StorageSize) TerminalString

func (s StorageSize) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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