Documentation ¶
Index ¶
- Variables
- func Decode(input string) ([]byte, error)
- func DecodeBig(input string) (*big.Int, error)
- func DecodeUint64(input string) (uint64, error)
- func Encode(b []byte) string
- func EncodeBig(bigint *big.Int) string
- func EncodeUint64(i uint64) string
- func InitDB() *gorm.DB
- func MustDecode(input string) []byte
- func MustDecodeBig(input string) *big.Int
- func MustDecodeUint64(input string) uint64
- func Request(url string, method string, data string, Headers map[string]string, ...) string
- func StructFor(input interface{})
- func StructPrint(input interface{})
- type Metrics
- type Session
- func (s *Session) AddIndex(dbName string, collectionName string, indexKeys interface{})
- func (s *Session) AddIndexSingle(dbName string, collectionName string, Key string, Desc int, SetUnique bool)
- func (s *Session) Find(dbName, collectionName string, filter interface{}, ...) (results []bson.M, err error)
- func (s *Session) FindOne(dbName, collectionName string, filter interface{}, ret interface{}, ...) (notFind bool, err error)
- func (s *Session) InitMongoDB() error
- func (s *Session) InsertMany(dbName, collectionName string, doc []interface{}) *mongo.InsertManyResult
- func (s *Session) InsertOne(dbName, collectionName string, doc interface{}, ctx ...context.Context) *mongo.InsertOneResult
Constants ¶
This section is empty.
Variables ¶
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 DecodeBig ¶ added in v1.0.13
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
将 0x 开头的16进制字符串解析为 unint64
func InitDB ¶
----------------------------------------------------------------------------- 初始化数据库连接
func MustDecode ¶ added in v1.0.13
MustDecode decodes a hex string with 0x prefix. It panics for invalid input.
func MustDecodeBig ¶ added in v1.0.13
MustDecodeBig decodes a hex string with 0x prefix as a quantity. It panics for invalid input.
func MustDecodeUint64 ¶ added in v1.0.13
MustDecodeUint64 decodes a hex string with 0x prefix as a quantity. It panics for invalid input.
Types ¶
type Metrics ¶
type Metrics map[string][]metriceInfo
定义用于存储所有指标的 Map
func InitPrometheus ¶
指定基本信息,并初始化客户端
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) WriteTextfile ¶
将结果编码为 Prometheus 文本格式
type Session ¶
type Session struct { Client *mongo.Client Options options.IndexOptions FindOneOptions options.FindOneOptions FindOptions options.FindOptions // contains filtered or unexported fields }
func (*Session) AddIndex ¶ added in v1.0.9
创建索引(可以弃用了) 参考: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) InsertMany ¶
func (s *Session) InsertMany(dbName, collectionName string, doc []interface{}) *mongo.InsertManyResult
插入多条数据