tools

package module
v1.0.33 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyString   = &decError{"empty hex string"}
	ErrSyntax        = &decError{"invalid hex string"}
	ErrMissingPrefix = &decError{"hex string without 0x prefix"}
	ErrOddLength     = &decError{"hex string of odd length"}
	ErrEmptyNumber   = &decError{"hex string \"0x\""}
	ErrLeadingZero   = &decError{"hex number with leading zero digits"}
	ErrUint64Range   = &decError{"hex number > 64 bits"}
	ErrUintRange     = &decError{fmt.Sprintf("hex number > %d bits", uintBits)}
	ErrBig256Range   = &decError{"hex number > 256 bits"}
)

Errors

Functions

func Decode added in v1.0.13

func Decode(input string) ([]byte, error)

Decode decodes a hex string with 0x prefix.

func DecodeBig added in v1.0.13

func DecodeBig(input string) (*big.Int, error)

DecodeBig decodes a hex string with 0x prefix as a quantity. Numbers larger than 256 bits are not accepted.

func DecodeUint64 added in v1.0.13

func DecodeUint64(input string) (uint64, error)

将 0x 开头的16进制字符串解析为 unint64

func Encode added in v1.0.13

func Encode(b []byte) string

Encode encodes b as a hex string with 0x prefix.

func EncodeBig added in v1.0.13

func EncodeBig(bigint *big.Int) string

EncodeBig encodes bigint as a hex string with 0x prefix.

func EncodeUint64

func EncodeUint64(i uint64) string

uint64 解码为 0x 开头的16进制字符串

func InitDB

func InitDB() *gorm.DB

----------------------------------------------------------------------------- 初始化数据库连接

func MustDecode added in v1.0.13

func MustDecode(input string) []byte

MustDecode decodes a hex string with 0x prefix. It panics for invalid input.

func MustDecodeBig added in v1.0.13

func MustDecodeBig(input string) *big.Int

MustDecodeBig decodes a hex string with 0x prefix as a quantity. It panics for invalid input.

func MustDecodeUint64 added in v1.0.13

func MustDecodeUint64(input string) uint64

MustDecodeUint64 decodes a hex string with 0x prefix as a quantity. It panics for invalid input.

func Request

func Request(url string, method string, data string, Headers map[string]string, parms map[string]string) string

func StructFor

func StructFor(input interface{})

遍历结构体

func StructPrint

func StructPrint(input interface{})

打印结构体

Types

type Metrics

type Metrics map[string][]metriceInfo

定义用于存储所有指标的 Map

func InitPrometheus

func InitPrometheus(NameSpace string, SubSystem string) Metrics

指定基本信息,并初始化客户端

func (Metrics) AddGaugeVec

func (metricser Metrics) AddGaugeVec(Name string, Help string, Labels map[string]string, Value float64)

添加 Gauge 指标(静态添加) func AddGaugeVec(Name string, Help string, Labels map[string]string, Value float64) {

func (Metrics) PrintMetrics

func (metrics Metrics) PrintMetrics()

直接打印所有指标

func (Metrics) WriteTextfile

func (metricser Metrics) WriteTextfile(filename string) error

将结果编码为 Prometheus 文本格式

type Session

type Session struct {
	Client *mongo.Client

	Options        options.IndexOptions
	FindOneOptions options.FindOneOptions
	FindOptions    options.FindOptions
	// contains filtered or unexported fields
}

func New

func New(uri string) *Session

func (*Session) AddIndex added in v1.0.9

func (s *Session) AddIndex(dbName string, collectionName string, indexKeys interface{})

创建索引(可以弃用了) 参考:https://stackoverflow.com/questions/56759074/how-do-i-create-a-text-index-in-mongodb-with-golang-and-the-mongo-go-driver

func (*Session) AddIndexSingle added in v1.0.17

func (s *Session) AddIndexSingle(dbName string, collectionName string, Key string, Desc int, SetUnique bool)

创建单字段索引(优化使用) 参考:https://stackoverflow.com/questions/56759074/how-do-i-create-a-text-index-in-mongodb-with-golang-and-the-mongo-go-driver

func (*Session) Find added in v1.0.11

func (s *Session) Find(dbName, collectionName string, filter interface{}, opts ...*options.FindOptions) (results []bson.M, err error)

查找多条数据

func (*Session) FindOne

func (s *Session) FindOne(dbName, collectionName string, filter interface{}, ret interface{}, opts ...*options.FindOneOptions) (notFind bool, err error)

查找一条数据

func (*Session) InitMongoDB

func (s *Session) InitMongoDB() error

初始化数据库

func (*Session) InsertMany

func (s *Session) InsertMany(dbName, collectionName string, doc []interface{}) *mongo.InsertManyResult

插入多条数据

func (*Session) InsertOne

func (s *Session) InsertOne(dbName, collectionName string, doc interface{}, ctx ...context.Context) *mongo.InsertOneResult

插入一条数据

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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