hc

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: Apache-2.0 Imports: 32 Imported by: 0

README

hc

介绍

{以下是 Gitee 平台说明,您可以替换此简介 Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 https://gitee.com/enterprises}

软件架构

软件架构说明

安装教程
  1. xxxx
  2. xxxx
  3. xxxx
使用说明
  1. xxxx
  2. xxxx
  3. xxxx
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
特技
  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/

Documentation

Index

Constants

View Source
const (
	DefaultRPCPath   = "/_goRPC_"
	DefaultDebugPath = "/debug/rpc"
)

Defaults used by HandleHTTP

Variables

View Source
var (
	RegisterAddress = ":8500" // RegisterAddress 注册中心地址
	Weight          = 1       // 权重
)

Register注册相关配置变量

View Source
var (
	// Epoch is set to the twitter snowflake epoch of Nov 04 2010 01:42:54 UTC in milliseconds
	// You may customize this to set a different epoch for your application.
	Epoch int64 = 1288834974657

	// NodeBits holds the number of bits to use for Node
	// Remember, you have a total 22 bits to share between Node/Step
	NodeBits uint8 = 10

	// StepBits holds the number of bits to use for Step
	// Remember, you have a total 22 bits to share between Node/Step
	StepBits uint8 = 12
)
View Source
var (
	ServiceName = "rpc" // 服务名
	LogDir      = "."   // 日志路径
	Debug       = false // 调试模式

)

变量

View Source
var DefaultServer = NewServer()

DefaultServer is the default instance of *Server.

View Source
var ErrInvalidBase32 = errors.New("invalid base32")

ErrInvalidBase32 is returned by ParseBase32 when given an invalid []byte

View Source
var ErrInvalidBase58 = errors.New("invalid base58")

ErrInvalidBase58 is returned by ParseBase58 when given an invalid []byte

View Source
var ErrNil = redis.ErrNil

ErrNil reids的ErrNil

View Source
var ErrNoRows = sql.ErrNoRows

ErrNoRows sql的ErrNoRows

View Source
var ErrShutdown = errors.New("connection is shut down")

ErrShutdown 连接已断开错误

Functions

func Accept

func Accept(lis net.Listener)

Accept accepts connections on the listener and serves requests to DefaultServer for each incoming connection. Accept blocks; the caller typically invokes it in a go statement.

func DBConn

func DBConn(driverName, dataSourceName string) (err error)

DBConn 连接数据库

func Disover

func Disover(address string) (err error)

Disover 发现服务 address 注册中心的地址

func GetOffset

func GetOffset(page, pageSize int) int

GetOffset 根据当前页和每页数量, 获取sql查询的偏移量

func GetZRange

func GetZRange(page, pageSize int) (start, end int)

GetZRange 根据当前页和每页数量, 获取sql查询的偏移量

func HandleHTTP

func HandleHTTP()

HandleHTTP registers an HTTP handler for RPC messages to DefaultServer on DefaultRPCPath and a debugging handler on DefaultDebugPath. It is still necessary to invoke http.Serve(), typically in a go statement.

func InitLog

func InitLog()

InitLog 使用日志配置变量初始化日志

func JSONServeConn

func JSONServeConn(conn io.ReadWriteCloser)

JSONServeConn runs the JSON-RPC server on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement.

func ListenAndJSONServe

func ListenAndJSONServe(address string, port int) error

ListenAndJSONServe 启动jsonrpc服务

func ListenAndServe

func ListenAndServe(address string, port int) error

ListenAndServe 启动服务

func ParseTimeByUUID

func ParseTimeByUUID(uuid string) (dateTime string, err error)

ParseTimeByUUID 根据uuid, 获取生成该uuid的时间

func RandomString

func RandomString(length int) string

RandomString 生成随机字符串

func RedisConn

func RedisConn(host, port, password string, maxIDle, maxActive int) error

RedisConn Redis连接

func Register

func Register(rcvr interface{}) error

Register publishes the receiver's methods in the DefaultServer.

func RegisterName

func RegisterName(name string, rcvr interface{}) error

RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.

func ServeCodec

func ServeCodec(codec ServerCodec)

ServeCodec is like ServeConn but uses the specified codec to decode requests and encode responses.

func ServeConn

func ServeConn(conn io.ReadWriteCloser)

ServeConn runs the DefaultServer on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement. ServeConn uses the gob wire format (see package gob) on the connection. To use an alternate codec, use ServeCodec. See NewClient's comment for information about concurrent access.

func ServeRequest

func ServeRequest(codec ServerCodec) error

ServeRequest is like ServeCodec but synchronously serves a single request. It does not close the codec upon completion.

func Struct2Map

func Struct2Map(obj interface{}) map[string]interface{}

Struct2Map 结构体转map

func UUID

func UUID() (uuid string, err error)

UUID 生成uuid

Types

type Base

type Base struct {
	ClientURI   string `json:"clientURI"`   // 客户端请求地址
	StartTime   int64  `json:"startTime"`   // 服务器接收到客户端请求的时间
	RequestTime int64  `json:"requestTime"` // 请求当前当前服务的发起时间
	Platform    string `json:"platform"`    // 客户端的平台
	IP          string `json:"ip"`          // 客户端ip
	TraceID     string `json:"traceID"`     // traceID
	AppName     string `json:"appName"`     // appName
	AppCode     string `json:"appCode"`     // appcode
	AppVersion  string `json:"appVersion"`  // appversion
	UUID        string `json:"uuid"`        // 用户uuid
	Username    string `json:"username"`    // 用户名
}

Base 存放一些请求的基本字段

type Call

type Call struct {
	ServiceMethod string      // The name of the service and method to call.
	Args          interface{} // The argument to the function (*struct).
	Reply         interface{} // The reply from the function (*struct).
	Error         error       // After completion, the error status.
	Done          chan *Call  // Receives *Call when Go is complete.
}

Call represents an active RPC.

type Client

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

Client represents an RPC Client. There may be multiple outstanding Calls associated with a single Client, and a Client may be used by multiple goroutines simultaneously.

func Connect

func Connect(serviceName string, args ...string) (*Client, error)

Connect 客户端连接 serviceName 注册中心的服务名 第二个参数决定使用jsonrpc还是默认go的rpc

func Dial

func Dial(network, address string) (*Client, error)

Dial connects to an RPC server at the specified network address.

func DialHTTP

func DialHTTP(network, address string) (*Client, error)

DialHTTP connects to an HTTP RPC server at the specified network address listening on the default HTTP RPC path.

func DialHTTPPath

func DialHTTPPath(network, address, path string) (*Client, error)

DialHTTPPath connects to an HTTP RPC server at the specified network address and path.

func JSONDial

func JSONDial(network, address string) (*Client, error)

JSONDial connects to a JSON-RPC server at the specified network address.

func NewClient

func NewClient(conn io.ReadWriteCloser) *Client

NewClient returns a new Client to handle requests to the set of services at the other end of the connection. It adds a buffer to the write side of the connection so the header and payload are sent as a unit.

The read and write halves of the connection are serialized independently, so no interlocking is required. However each half may be accessed concurrently so the implementation of conn should protect against concurrent reads or concurrent writes.

func NewClientWithCodec

func NewClientWithCodec(codec ClientCodec) *Client

NewClientWithCodec is like NewClient but uses the specified codec to encode requests and decode responses.

func NewJSONClient

func NewJSONClient(conn io.ReadWriteCloser) *Client

NewJSONClient returns a new Client to handle requests to the set of services at the other end of the connection.

func (*Client) Call

func (client *Client) Call(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error

Call invokes the named function, waits for it to complete, and returns its error status.

func (*Client) Close

func (client *Client) Close() error

Close calls the underlying codec's Close method. If the connection is already shutting down, ErrShutdown is returned.

func (*Client) Go

func (client *Client) Go(ctx context.Context, serviceMethod string, args interface{}, reply interface{}, done chan *Call) *Call

Go invokes the function asynchronously. It returns the Call structure representing the invocation. The done channel will signal when the call is complete by returning the same Call object. If done is nil, Go will allocate a new channel. If non-nil, done must be buffered or Go will deliberately crash.

type ClientCodec

type ClientCodec interface {
	WriteRequest(*Request, *Base, interface{}) error
	ReadResponseHeader(*Response) error
	ReadResponseBody(interface{}) error

	Close() error
}

A ClientCodec implements writing of RPC requests and reading of RPC responses for the client side of an RPC session. The client calls WriteRequest to write a request to the connection and calls ReadResponseHeader and ReadResponseBody in pairs to read responses. The client calls Close when finished with the connection. ReadResponseBody may be called with a nil argument to force the body of the response to be read and then discarded. See NewClient's comment for information about concurrent access.

func NewClientCodec

func NewClientCodec(conn io.ReadWriteCloser) ClientCodec

NewClientCodec returns a new ClientCodec using JSON-RPC on conn.

type ContextKey

type ContextKey string

ContextKey context的key类型

type ID

type ID int64

An ID is a custom type used for a snowflake ID. This is used so we can attach methods onto the ID.

func ParseBase2

func ParseBase2(id string) (ID, error)

ParseBase2 converts a Base2 string into a snowflake ID

func ParseBase32

func ParseBase32(b []byte) (ID, error)

ParseBase32 parses a base32 []byte into a snowflake ID NOTE: There are many different base32 implementations so becareful when doing any interoperation.

func ParseBase36

func ParseBase36(id string) (ID, error)

ParseBase36 converts a Base36 string into a snowflake ID

func ParseBase58

func ParseBase58(b []byte) (ID, error)

ParseBase58 parses a base58 []byte into a snowflake ID

func ParseBase64

func ParseBase64(id string) (ID, error)

ParseBase64 converts a base64 string into a snowflake ID

func ParseBytes

func ParseBytes(id []byte) (ID, error)

ParseBytes converts a byte slice into a snowflake ID

func ParseInt64

func ParseInt64(id int64) ID

ParseInt64 converts an int64 into a snowflake ID

func ParseIntBytes

func ParseIntBytes(id [8]byte) ID

ParseIntBytes converts an array of bytes encoded as big endian integer as a snowflake ID

func ParseString

func ParseString(id string) (ID, error)

ParseString converts a string into a snowflake ID

func (ID) Base2

func (f ID) Base2() string

Base2 returns a string base2 of the snowflake ID

func (ID) Base32

func (f ID) Base32() string

Base32 uses the z-base-32 character set but encodes and decodes similar to base58, allowing it to create an even smaller result string. NOTE: There are many different base32 implementations so becareful when doing any interoperation.

func (ID) Base36

func (f ID) Base36() string

Base36 returns a base36 string of the snowflake ID

func (ID) Base58

func (f ID) Base58() string

Base58 returns a base58 string of the snowflake ID

func (ID) Base64

func (f ID) Base64() string

Base64 returns a base64 string of the snowflake ID

func (ID) Bytes

func (f ID) Bytes() []byte

Bytes returns a byte slice of the snowflake ID

func (ID) Int64

func (f ID) Int64() int64

Int64 returns an int64 of the snowflake ID

func (ID) IntBytes

func (f ID) IntBytes() [8]byte

IntBytes returns an array of bytes of the snowflake ID, encoded as a big endian integer.

func (ID) MarshalJSON

func (f ID) MarshalJSON() ([]byte, error)

MarshalJSON returns a json byte array string of the snowflake ID.

func (ID) Node

func (f ID) Node() int64

Node returns an int64 of the snowflake ID node number DEPRECATED: the below function will be removed in a future release.

func (ID) Step

func (f ID) Step() int64

Step returns an int64 of the snowflake step (or sequence) number DEPRECATED: the below function will be removed in a future release.

func (ID) String

func (f ID) String() string

String returns a string of the snowflake ID

func (ID) Time

func (f ID) Time() int64

Time returns an int64 unix timestamp in milliseconds of the snowflake ID time DEPRECATED: the below function will be removed in a future release.

func (*ID) UnmarshalJSON

func (f *ID) UnmarshalJSON(b []byte) error

UnmarshalJSON converts a json byte array of a snowflake ID into an ID type.

type JSONSyntaxError

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

A JSONSyntaxError is returned from UnmarshalJSON if an invalid ID is provided.

func (JSONSyntaxError) Error

func (j JSONSyntaxError) Error() string

type LogBase

type LogBase struct {
	ClientURI    string `json:"clientURI"`    // 客户端请求地址
	URI          string `json:"uri"`          // 当前服务被请求地址(service/receiver/method)
	StartTime    int64  `json:"startTime"`    // 服务器接收到客户端请求的时间
	RequestTime  int64  `json:"requestTime"`  // 请求当前当前服务的发起时间
	Platform     string `json:"platform"`     // 客户端的平台
	SpanLog      bool   `json:"spanLog"`      // 是否是span日志
	IP           string `json:"ip"`           // 客户端ip
	TraceID      string `json:"traceID"`      // traceID
	AppName      string `json:"appName"`      // appName
	AppCode      string `json:"appCode"`      // appCode
	AppVersion   string `json:"appVersion"`   // appVersion
	ReceiveTime  int64  `json:"receiveTime"`  // 当前服务接收到请求的时间
	ResponseTime int64  `json:"responseTime"` // 当前服务响应请求的时间
}

LogBase 日志基础信息

type LoggerObj

type LoggerObj struct {
	*zap.Logger
}

LoggerObj zap日志

var (
	InfoLogger  LoggerObj // info级别日志
	DebugLogger LoggerObj // debug级别日志
	WarnLogger  LoggerObj // warn级别日志
	ErrorLogger LoggerObj // error级别日志

)

日志变量

type LoggerWithBase

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

LoggerWithBase LoggerWithBase

func Log

func Log(ctx context.Context) *LoggerWithBase

Log 使用Context相关参数

func (*LoggerWithBase) Debug

func (l *LoggerWithBase) Debug(msg string, fields ...interface{})

Debug debug日志实现

func (*LoggerWithBase) Error

func (l *LoggerWithBase) Error(msg string, fields ...interface{})

Error error日志实现

func (*LoggerWithBase) Info

func (l *LoggerWithBase) Info(msg string, fields ...interface{})

Info info日志实现

func (*LoggerWithBase) Warn

func (l *LoggerWithBase) Warn(msg string, fields ...interface{})

Warn warn日志实现

type Node

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

A Node struct holds the basic information needed for a snowflake generator node

func (*Node) Generate

func (n *Node) Generate() ID

Generate creates and returns a unique snowflake ID To help guarantee uniqueness - Make sure your system is keeping accurate system time - Make sure you never have multiple nodes running with the same node ID

type RedisArgs

type RedisArgs = redis.Args

RedisArgs redis.Args类型的别名

type RedisPool

type RedisPool struct {
	Pool *redis.Pool
}

RedisPool redis连接池

var Redis *RedisPool

Redis 存放redis连接池的变量

func (*RedisPool) DEL

func (p *RedisPool) DEL(key string) error

DEL 删除一个key

func (*RedisPool) EXISTS

func (p *RedisPool) EXISTS(key string) (bool, error)

EXISTS 检查一个建是否存在

func (*RedisPool) EXPIRE

func (p *RedisPool) EXPIRE(key string, seconds int) error

EXPIRE 设置key的有效期

func (*RedisPool) GET

func (p *RedisPool) GET(key string) (value string, err error)

GET 返回与键 key 相关联的字符串值。

func (*RedisPool) HDEL

func (p *RedisPool) HDEL(key string, fields ...string) (count int, err error)

HDEL 删除哈希表 key 中的一个或多个指定域,不存在的域将被忽略。 返回值: 被成功移除的域的数量,不包括被忽略的域。

func (*RedisPool) HGET

func (p *RedisPool) HGET(key, field string) (value string, err error)

HGET 返回哈希表中给定域的值。

func (*RedisPool) HGETALL

func (p *RedisPool) HGETALL(key string, out interface{}) (err error)

HGETALL 返回哈希表 key 中,所有的域和值,并赋值给out(out是一个结构体的指针) out 字段使用"redis" tag 作匹配

func (*RedisPool) HINCRBY

func (p *RedisPool) HINCRBY(key, field string, increment int64) (value int64, err error)

HINCRBY 为哈希表 key 中的域 field 的值加上增量 increment 。 增量也可以为负数,相当于对给定域进行减法操作。 如果 key 不存在,一个新的哈希表被创建并执行 HINCRBY 命令。 如果域 field 不存在,那么在执行命令前,域的值被初始化为 0 。 对一个储存字符串值的域 field 执行 HINCRBY 命令将造成一个错误。 本操作的值被限制在 64 位(bit)有符号数字表示之内。 返回值: 执行 HINCRBY 命令之后,哈希表 key 中域 field 的值。

func (*RedisPool) HINCRBYFLOAT

func (p *RedisPool) HINCRBYFLOAT(key, field string, increment float64) (value float64, err error)

HINCRBYFLOAT 为哈希表 key 中的域 field 加上浮点数增量 increment 。 如果哈希表中没有域 field ,那么 HINCRBYFLOAT 会先将域 field 的值设为 0 ,然后再执行加法操作。 如果键 key 不存在,那么 HINCRBYFLOAT 会先创建一个哈希表,再创建域 field ,最后再执行加法操作。 无论加法计算所得的浮点数的实际精度有多长, INCRBYFLOAT 命令的计算结果最多只保留小数点的后十七位。 当以下任意一个条件发生时,返回一个错误:

1.域 field 的值不是字符串类型(因为 redis 中的数字和浮点数都以字符串的形式保存,所以它们都属于字符串类型)
2.域 field 当前的值或给定的增量 increment 不能解释(parse)为双精度浮点数

返回值: 执行加法操作之后 field 域的值。

func (*RedisPool) HMGET

func (p *RedisPool) HMGET(key string, fields ...string) (value map[string]string, err error)

HMGET 返回哈希表 key 中,一个或多个给定域的值。 如果给定的域不存在于哈希表,那么返回一个 nil 值。 因为不存在的 key 被当作一个空哈希表来处理,所以对一个不存在的 key 进行 HMGET 操作将返回一个只带有 nil 值的表。

func (*RedisPool) HSET

func (p *RedisPool) HSET(key string, fieldValue interface{}) (err error)

-------------------------------------------------------------------------------------------------------------// ---------------------------------------------------- hash ----------------------------------------------------// HSET 作同时将多个 field-value (域-值)对设置到哈希表 key 中 此命令会覆盖哈希表中已存在的域

func (*RedisPool) INCR

func (p *RedisPool) INCR(key string) (value int64, err error)

INCR 为键 key 储存的数字值加上一。 如果键 key 不存在, 那么它的值会先被初始化为 0 , 然后再执行 INCR 命令。 如果键 key 储存的值不能被解释为数字, 那么 INCR 命令将返回一个错误。 本操作的值限制在 64 位(bit)有符号数字表示之内。 返回值: INCR 命令会返回键 key 在执行加一操作之后的值。

func (*RedisPool) INCRBY

func (p *RedisPool) INCRBY(key string, increment int64) (value int64, err error)

INCRBY 为键 key 储存的数字值加上增量 increment 。 如果键 key 不存在, 那么键 key 的值会先被初始化为 0 , 然后再执行 INCRBY 命令。 如果键 key 储存的值不能被解释为数字, 那么 INCRBY 命令将返回一个错误。 本操作的值限制在 64 位(bit)有符号数字表示之内。 返回值: 在加上增量 increment 之后, 键 key 的值。

func (*RedisPool) INCRBYFLOAT

func (p *RedisPool) INCRBYFLOAT(key string, increment float64) (value float64, err error)

INCRBYFLOAT 为键 key 储存的值加上浮点数增量 increment 。 如果键 key 不存在, 那么 INCRBYFLOAT 会先将键 key 的值设为 0 , 然后再执行加法操作。 如果命令执行成功, 那么键 key 的值会被更新为执行加法计算之后的新值, 并且新值会以字符串的形式返回给调用者。 无论加法计算所得的浮点数的实际精度有多长, INCRBYFLOAT 命令的计算结果最多只保留小数点的后十七位。 当以下任意一个条件发生时, 命令返回一个错误:

键 key 的值不是字符串类型(因为 Redis 中的数字和浮点数都以字符串的形式保存,所以它们都属于字符串类型);
1.键 key 当前的值或者给定的增量 increment 不能被解释(parse)为双精度浮点数。

本操作的值限制在 64 位(bit)有符号数字表示之内。 返回值: 在加上增量 increment 之后, 键 key 的值。

func (*RedisPool) SADD

func (p *RedisPool) SADD(args ...interface{}) error

SADD 将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略。 假如 key 不存在,则创建一个只包含 member 元素作成员的集合。 当 key 不是集合类型时,返回一个错误。

func (*RedisPool) SCARD

func (p *RedisPool) SCARD(key string) (score int, err error)

SCARD 返回集合 key 的基数(集合中元素的数量)。 集合的基数。 当 key 不存在时,返回 0 。

func (*RedisPool) SET

func (p *RedisPool) SET(key, value string) error

SET 将字符串值 value 关联到 key 。 如果 key 已经持有其他值, SET 就覆写旧值, 无视类型。 特别注意:无视类型覆盖 当 SET 命令对一个带有生存时间(TTL)的键进行设置之后, 该键原有的 TTL 将被清除。

func (*RedisPool) SISMEMBER

func (p *RedisPool) SISMEMBER(key string, value string) (bool, error)

SISMEMBER 判断 value 元素是否集合 key 的成员 如果 member 元素是集合的成员,返回 true 。 如果 member 元素不是集合的成员,或 key 不存在,返回 false 。

func (*RedisPool) SMEMBERS

func (p *RedisPool) SMEMBERS(key string) ([]string, error)

SMEMBERS 返回集合 key 中的所有成员。 不存在的 key 被视为空集合。

func (*RedisPool) SREM

func (p *RedisPool) SREM(key string, member ...interface{}) error

SREM 移除集合 key 中的一个或多个 member 元素,不存在的 member 元素会被忽略。 当 key 不是集合类型,返回一个错误。

func (*RedisPool) ZADD

func (p *RedisPool) ZADD(key string, scoreMember interface{}) error

-------------------------------------------------------------------------------------------------------------// ---------------------------------------------------- zset ----------------------------------------------------// ZADD 将一个或多个 member 元素及其 score 值加入到有序集 key 当中。 如果某个 member 已经是有序集的成员,那么更新这个 member 的 score 值,并通过重新插入这个 member 元素,来保证该 member 在正确的位置上。 score 值可以是整数值或双精度浮点数。 如果 key 不存在,则创建一个空的有序集并执行 ZADD 操作。 当 key 存在但不是有序集类型时,返回一个错误。

使用例子:

 scoreMember := map[int]string{111: "a", 101: "b"}
	if err := conn.ZADD("testZSET", scoreMember); err != nil {
		t.Error(err)
 }

func (*RedisPool) ZCARD

func (p *RedisPool) ZCARD(key string) (score int, err error)

ZCARD 返回有序集 key 的基数(集合中元素的数量)。 当 key 存在且是有序集类型时,返回有序集的基数。 当 key 不存在时,返回 0 。

func (*RedisPool) ZCOUNT

func (p *RedisPool) ZCOUNT(key string, min, max float64) (count int64, err error)

ZCOUNT 返回有序集 key 中, score 值在 min 和 max 之间(默认包括 score 值等于 min 或 max )的成员的数量。 返回值: score 值在 min 和 max 之间的成员的数量。

func (*RedisPool) ZINCRBY

func (p *RedisPool) ZINCRBY(key string, increment, member interface{}) (score string, err error)

ZINCRBY 为有序集 key 的成员 member 的 score 值加上增量 increment 。 可以通过传递一个负数值 increment ,让 score 减去相应的值,比如 ZINCRBY key -5 member ,就是让 member 的 score 值减去 5 当 key 不存在,或 member 不是 key 的成员时, ZINCRBY key increment member 等同于 ZADD key increment member 。 当 key 不是有序集类型时,返回一个错误。 score 值可以是整数值或双精度浮点数。

func (*RedisPool) ZRANGE

func (p *RedisPool) ZRANGE(key string, start, stop int64) (result []string, err error)

ZRANGE 返回有序集 key 中,指定区间内的成员。 其中成员的位置按 score 值递增(从小到大)来排序。 具有相同 score 值的成员按字典序(lexicographical order )来排列。 下标参数 start 和 stop 都以 0 为底,也就是说,以 0 表示有序集第一个成员,以 1 表示有序集第二个成员,以此类推。 你也可以使用负数下标,以 -1 表示最后一个成员, -2 表示倒数第二个成员,以此类推。 超出范围的下标并不会引起错误。 比如说,当 start 的值比有序集的最大下标还要大,或是 start > stop 时, ZRANGE 命令只是简单地返回一个空列表。 另一方面,假如 stop 参数的值比有序集的最大下标还要大,那么 Redis 将 stop 当作最大下标来处理。 返回值: 指定区间内的有序集成员的列表。

func (*RedisPool) ZRANGEWITHSCORES

func (p *RedisPool) ZRANGEWITHSCORES(key string, start, stop int64) (result []map[string]float64, err error)

ZRANGEWITHSCORES 使用WITHSCORES选项的ZRANGE

func (*RedisPool) ZRANK

func (p *RedisPool) ZRANK(key string, member interface{}) (rank int64, err error)

ZRANK 返回有序集 key 中成员 member 的排名。其中有序集成员按 score 值递增(从小到大)顺序排列。 排名以 0 为底,也就是说, score 值最小的成员排名为 0 。 使用 ZREVRANK key member 命令可以获得成员按 score 值递减(从大到小)排列的排名。 返回值:

如果 member 是有序集 key 的成员,返回 member 的排名。
如果 member 不是有序集 key 的成员,返回 -1。

func (*RedisPool) ZREM

func (p *RedisPool) ZREM(key string, member ...interface{}) (count int64, err error)

ZREM 移除有序集 key 中的一个或多个成员,不存在的成员将被忽略。

func (*RedisPool) ZREMRANGEBYRANK added in v0.0.3

func (p *RedisPool) ZREMRANGEBYRANK(key string, start, stop int64) (count int64, err error)

ZREMRANGEBYRANK 移除有序集key中,指定排名(rank)区间 start 和 stop 内的所有成员。 下标参数start和stop都是从0开始计数,0是分数最小的那个元素。 索引也可是负数,表示位移从最高分处开始数。 例如,-1是分数最高的元素,-2是分数第二高的,依次类推。

func (*RedisPool) ZREVRANGE

func (p *RedisPool) ZREVRANGE(key string, start, stop int64) (result []string, err error)

ZREVRANGE 返回有序集 key 中,指定区间内的成员。 其中成员的位置按 score 值递减(从大到小)来排序。 具有相同 score 值的成员按字典序的逆序(reverse lexicographical order)排列。 下标参数 start 和 stop 都以 0 为底,也就是说,以 0 表示有序集第一个成员,以 1 表示有序集第二个成员,以此类推。 你也可以使用负数下标,以 -1 表示最后一个成员, -2 表示倒数第二个成员,以此类推。 超出范围的下标并不会引起错误。 返回值: 指定区间内的有序集成员的列表。

func (*RedisPool) ZREVRANGEWITHSCORES

func (p *RedisPool) ZREVRANGEWITHSCORES(key string, start, stop int64) (result []map[string]float64, err error)

ZREVRANGEWITHSCORES 使用WITHSCORES选项的ZREVRANGE

func (*RedisPool) ZREVRANK

func (p *RedisPool) ZREVRANK(key string, member interface{}) (rank int64, err error)

ZREVRANK 返回有序集 key 中成员 member 的排名。其中有序集成员按 score 值递减(从大到小)顺序排列。 排名以 0 为底,也就是说, score 值最小的成员排名为 0 。 返回值:

  • 如果 member 是有序集 key 的成员,返回 member 的排名。
  • 如果 member 不是有序集 key 的成员,返回 -1。

func (*RedisPool) ZSCORE

func (p *RedisPool) ZSCORE(key string, member interface{}) (score string, err error)

ZSCORE 返回有序集 key 中,成员 member 的 score 值。 如果 member 元素不是有序集 key 的成员,或 key 不存在,返回 nil 。

type Request

type Request struct {
	ServiceMethod string // format: "Service.Method"
	Seq           uint64 // sequence number chosen by client
	// contains filtered or unexported fields
}

Request is a header written before every RPC call. It is used internally but documented here as an aid to debugging, such as when analyzing network traffic.

type Response

type Response struct {
	ServiceMethod string // echoes that of the Request
	Seq           uint64 // echoes that of the request
	Error         string // error, if any.
	// contains filtered or unexported fields
}

Response is a header written before every RPC return. It is used internally but documented here as an aid to debugging, such as when analyzing network traffic.

type SQLM

type SQLM struct {
	*sqlx.DB
}

SQLM SQLM

var DB SQLM

DB 数据库连接

func (SQLM) Begin

func (s SQLM) Begin() (tx Tx, err error)

Begin 开始事务

func (SQLM) Exec

func (s SQLM) Exec(pattern string, arg interface{}) (result sql.Result, err error)

Exec 执行一次数据操作

func (SQLM) Query

func (s SQLM) Query(pattern string, arg interface{}) (rows *sqlx.Rows, err error)

Query 执行一次多行查询

func (SQLM) QueryRow

func (s SQLM) QueryRow(pattern string, arg interface{}) (row *sqlx.Row, err error)

QueryRow 执行一次单行查询

type Server

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

Server represents an RPC Server.

func NewServer

func NewServer() *Server

NewServer returns a new Server.

func (*Server) Accept

func (server *Server) Accept(lis net.Listener)

Accept accepts connections on the listener and serves requests for each incoming connection. Accept blocks until the listener returns a non-nil error. The caller typically invokes Accept in a go statement.

func (*Server) HandleHTTP

func (server *Server) HandleHTTP(rpcPath, debugPath string)

HandleHTTP registers an HTTP handler for RPC messages on rpcPath, and a debugging handler on debugPath. It is still necessary to invoke http.Serve(), typically in a go statement.

func (*Server) Register

func (server *Server) Register(rcvr interface{}) error

Register publishes in the server the set of methods of the receiver value that satisfy the following conditions:

  • exported method of exported type
  • two arguments, both of exported type
  • the second argument is a pointer
  • one return value, of type error

It returns an error if the receiver is not an exported type or has no suitable methods. It also logs the error using package log. The client accesses each method using a string of the form "Type.Method", where Type is the receiver's concrete type.

func (*Server) RegisterName

func (server *Server) RegisterName(name string, rcvr interface{}) error

RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.

func (*Server) ServeCodec

func (server *Server) ServeCodec(codec ServerCodec)

ServeCodec is like ServeConn but uses the specified codec to decode requests and encode responses.

func (*Server) ServeConn

func (server *Server) ServeConn(conn io.ReadWriteCloser)

ServeConn runs the server on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement. ServeConn uses the gob wire format (see package gob) on the connection. To use an alternate codec, use ServeCodec. See NewClient's comment for information about concurrent access.

func (*Server) ServeHTTP

func (server *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implements an http.Handler that answers RPC requests.

func (*Server) ServeRequest

func (server *Server) ServeRequest(codec ServerCodec) error

ServeRequest 和ServeCodec类似,但是它是同步服务于单个请求. It does not close the codec upon completion.

type ServerCodec

type ServerCodec interface {
	ReadRequestHeader(*Request) error
	ReadRequestBase(*Base) error // 读取传递的一些基础参数
	ReadRequestBody(interface{}) error
	WriteResponse(*Response, interface{}) error

	// Close can be called multiple times and must be idempotent.
	Close() error
}

A ServerCodec implements reading of RPC requests and writing of RPC responses for the server side of an RPC session. The server calls ReadRequestHeader and ReadRequestBody in pairs to read requests from the connection, and it calls WriteResponse to write a response back. The server calls Close when finished with the connection. ReadRequestBody may be called with a nil argument to force the body of the request to be read and discarded. See NewClient's comment for information about concurrent access.

func NewServerCodec

func NewServerCodec(conn io.ReadWriteCloser) ServerCodec

NewServerCodec returns a new ServerCodec using JSON-RPC on conn.

type ServerError

type ServerError string

ServerError represents an error that has been returned from the remote side of the RPC connection.

func (ServerError) Error

func (e ServerError) Error() string

type Tx

type Tx struct {
	*sqlx.Tx
}

Tx sqlt事务对象

func (Tx) Commit

func (tx Tx) Commit() (err error)

Commit 提交事务

func (Tx) Exec

func (tx Tx) Exec(pattern string, arg interface{}) (result sql.Result, err error)

Exec 在事务中执行一次数据操作

func (Tx) Query

func (tx Tx) Query(pattern string, arg interface{}) (rows *sqlx.Rows, err error)

Query 在事务中执行一次多行查询

func (Tx) QueryRow

func (tx Tx) QueryRow(pattern string, arg interface{}) (row *sqlx.Row, err error)

QueryRow 在事务中执行一次单行查询

func (Tx) Rollback

func (tx Tx) Rollback() (err error)

Rollback 回滚事务

Jump to

Keyboard shortcuts

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