common

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: GPL-3.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64StdDecode

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

Base64StdDecode 自动解码传入的 base64 字节数组

func CatchUpFileID

func CatchUpFileID(loggerName, currentDay string) (int64, int64, error)

func CurrentDay

func CurrentDay(day time.Time) string

func DayTime

func DayTime(dayStr string) time.Time

func DirFileCount

func DirFileCount(dirPath string) int

func ExecuteFunctionByRetry

func ExecuteFunctionByRetry(f func() error) error

func GenChainID

func GenChainID(forkHeight int32) string

GenChainID 根据当前链所处的 fork 的区块高度作为该 chain 的唯一标识, TODO 存在不同 fork 高度相同的情况,需要加以区分

func GenEventOrphanTableName added in v0.0.2

func GenEventOrphanTableName(exporterTag string, timestamp Timestamp) string

func GenExporterInfoKey

func GenExporterInfoKey(exporterTag string) string

func GenLogFileParentPath

func GenLogFileParentPath(basePath, loggerName string, day string) string

GenLogFileParentPath basePath/loggerName/day/

func GenLogFilename

func GenLogFilename(id int64) string

func GenLogFilepath

func GenLogFilepath(basePath, loggerName string, day string, id int64) string

GenLogFilepath basePath/loggerName/day/id.log

func GenResolverTag

func GenResolverTag(exporterTag string) string

func GenRevisionTableName

func GenRevisionTableName(exporterTag string, timestamp Timestamp) string

func GenSnapshotDataTableName

func GenSnapshotDataTableName(exporterTag string, timestamp Timestamp) string

func GenSnapshotID

func GenSnapshotID(targetChainID string, targetChainHeight int32, initTimestamp Timestamp) string

func GenSnapshotSyncTableName

func GenSnapshotSyncTableName(exporterTag string, timestamp Timestamp) string

func GenStateTableName

func GenStateTableName(exporterTag string, timestamp Timestamp) string

func IsDirExisted

func IsDirExisted(dirPath string) bool

func IsFileExisted

func IsFileExisted(filePath string) bool

func LookupEnv

func LookupEnv(envKey string) (string, error)

LookupEnv 根据所有 key 查找环境变量,并通过 map 保存,如果中途有 error 不会直接中断,而是继续

func LookupEnvPairs

func LookupEnvPairs(envPairs *map[string]string)

LookupEnvPairs 根据所有 key 查找环境变量,并通过 map 保存,如果中途有 error 不会直接中断,而是继续

func ParseChainIDFromSnapshotID

func ParseChainIDFromSnapshotID(snapshotID string) string

func ParseExporterTagFromExporterInfoKey

func ParseExporterTagFromExporterInfoKey(exporterInfoKey string) string

func ScanFileLines

func ScanFileLines(filePath string, startN int64) ([][]byte, bool, error)

ScanFileLines 从 startN 处开始,scan 数据到达文件结尾,返回数据数组,eof 和 error, eof 判断是按照自定义的一行来判断的,注意这里潜在的问题是 logger 与 exporter 读写竞争可能导致日志输出到错误的 day, 所以在 resolver 处理时,只依赖数据本身,不依赖 logger 的信息,logger 和 exporter 只需要保证不丢数据就行

func StructToJsonStr

func StructToJsonStr(s any) string

Types

type Timestamp

type Timestamp int64

Timestamp 是 19 位长,精确到纳秒的时间戳

func FromInt64

func FromInt64(t int64) Timestamp

func FromNow

func FromNow() Timestamp

func FromTime

func FromTime(t time.Time) Timestamp

func (Timestamp) Format

func (t Timestamp) Format(layout string) string

func (Timestamp) FormatString

func (t Timestamp) FormatString() string

func (Timestamp) FormatTime

func (t Timestamp) FormatTime() time.Time

func (Timestamp) String

func (t Timestamp) String() string

Jump to

Keyboard shortcuts

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