hbtp

package module
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: Apache-2.0 Imports: 15 Imported by: 16

README

HyperByte Transfer Protocol

介绍

轻量级C/S通信协议,可在长连接、短连接之间反复横跳 (-_-||)!!!

软件架构

软件架构说明

安装教程
  1. xxxx
  2. xxxx
  3. xxxx
使用说明
  1. xxxx
  2. xxxx
  3. xxxx
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
特技

Documentation

Index

Constants

View Source
const (
	// Status is int32
	ResStatusOk       int32 = 1
	ResStatusErr      int32 = 2
	ResStatusAuth     int32 = 3
	ResStatusNotFound int32 = 4
)

Variables

View Source
var Debug = false

Functions

func BigByteToFloat32

func BigByteToFloat32(data []byte) float32

BigEndian

func BigByteToFloat64

func BigByteToFloat64(data []byte) float64

func BigByteToInt

func BigByteToInt(data []byte) int64

BigEndian

func BigFloatToByte32

func BigFloatToByte32(data float32) []byte

func BigFloatToByte64

func BigFloatToByte64(data float64) []byte

func BigIntToByte

func BigIntToByte(data int64, ln int) []byte

func Byte2Struct

func Byte2Struct(data []byte, pt interface{}) error

func Bytes2Struct

func Bytes2Struct(data []byte, pt unsafe.Pointer) error

func Debugf

func Debugf(s string, args ...interface{})

func DoJson

func DoJson(req *Request, in, out interface{}, hd ...Map) error

func DoString

func DoString(req *Request, in interface{}, hd ...Map) (int32, []byte, error)

func EndContext

func EndContext(ctx context.Context) bool

func Errorf added in v1.1.5

func Errorf(s string, args ...interface{})

func Infof added in v1.1.1

func Infof(s string, args ...interface{})

func LitByteToFloat32

func LitByteToFloat32(data []byte) float32

LittleEndian

func LitByteToFloat64

func LitByteToFloat64(data []byte) float64

func LitByteToInt

func LitByteToInt(data []byte) int64

LittleEndian

func LitFloatToByte32

func LitFloatToByte32(data float32) []byte

func LitFloatToByte64

func LitFloatToByte64(data float64) []byte

func LitIntToByte

func LitIntToByte(data int64, ln int) []byte

func PathExists

func PathExists(path string) bool

func SizeOf added in v1.0.1

func SizeOf(data interface{}) int

func SizeTOf added in v1.0.1

func SizeTOf(data interface{}) int

func Struct2Byte

func Struct2Byte(pt interface{}) ([]byte, error)

func Struct2ByteLen added in v1.0.1

func Struct2ByteLen(pt interface{}, ln int) ([]byte, error)

func Struct2Bytes

func Struct2Bytes(pt unsafe.Pointer, ln int) ([]byte, error)

func TcpRead

func TcpRead(ctx context.Context, conn net.Conn, ln uint) ([]byte, error)

Types

type AuthFun

type AuthFun = func(c *Context) bool

type Config

type Config struct {
	TmsInfo time.Duration
	TmsHead time.Duration
	TmsBody time.Duration
}

func MakeConfig

func MakeConfig() Config

type ConnFun

type ConnFun func(res *Context)

返回true则连接不会关闭

func GrpcFunHandle

func GrpcFunHandle(t IRPCRoute) ConnFun

func ParamFunHandle

func ParamFunHandle(fn interface{}, authfn ...AuthFun) ConnFun

type Context

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

func ParseContext

func ParseContext(ctx context.Context, conn net.Conn, cfg Config) (*Context, error)

func (*Context) Args

func (c *Context) Args() url.Values

func (*Context) BodyBytes

func (c *Context) BodyBytes() []byte

func (*Context) Command

func (c *Context) Command() string

func (*Context) Conn

func (c *Context) Conn(ownership ...bool) net.Conn

func (*Context) Control

func (c *Context) Control() int32

func (*Context) GetData

func (c *Context) GetData(k string) (interface{}, bool)

func (*Context) HeadBytes

func (c *Context) HeadBytes() []byte

func (*Context) IsOwn

func (c *Context) IsOwn() bool

func (*Context) ReqHeader

func (c *Context) ReqHeader() *Map

func (*Context) ResBytes

func (c *Context) ResBytes(code int32, bdbts []byte, hds ...[]byte) error

func (*Context) ResHeader

func (c *Context) ResHeader() *Map

func (*Context) ResJson

func (c *Context) ResJson(code int32, body interface{}, hds ...[]byte) error

func (*Context) ResString

func (c *Context) ResString(code int32, s string, hds ...[]byte) error

func (*Context) Sended added in v1.1.5

func (c *Context) Sended() bool

func (*Context) SetData

func (c *Context) SetData(k string, data interface{})

type Engine

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

func NewEngine

func NewEngine(ctx context.Context) *Engine

func (*Engine) Config

func (c *Engine) Config(conf Config)

func (*Engine) NotFoundFun

func (c *Engine) NotFoundFun(fn ConnFun)

func (*Engine) RegFun

func (c *Engine) RegFun(control int32, fn ConnFun) bool

func (*Engine) RegGrpcFun

func (c *Engine) RegGrpcFun(control int32, rpc IRPCRoute) bool

func (*Engine) RegParamFun

func (c *Engine) RegParamFun(control int32, fn interface{}) bool

func (*Engine) Run

func (c *Engine) Run(host string) error

func (*Engine) Stop

func (c *Engine) Stop()

type IRPCRoute

type IRPCRoute interface {
	AuthFun() AuthFun
}

type Map

type Map map[string]interface{}

func NewMap

func NewMap() *Map

func NewMaps

func NewMaps(body interface{}) *Map

func (*Map) Get

func (e *Map) Get(key string) (interface{}, bool)

func (*Map) GetBool

func (e *Map) GetBool(key string) bool

func (*Map) GetFloat

func (e *Map) GetFloat(key string) (float64, error)

func (*Map) GetInt

func (e *Map) GetInt(key string) (int64, error)

func (*Map) GetString

func (e *Map) GetString(key string) string

func (*Map) Map

func (e *Map) Map() map[string]interface{}

func (*Map) Set

func (e *Map) Set(key string, val interface{})

func (*Map) ToBytes

func (e *Map) ToBytes() []byte

func (*Map) ToString

func (e *Map) ToString() string

type Request

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

func NewConnRequest

func NewConnRequest(conn net.Conn, control int32, timeout ...time.Duration) *Request

func NewRequest

func NewRequest(addr string, control int32, timeout ...time.Duration) *Request

func (*Request) Args

func (c *Request) Args(args url.Values) *Request

func (*Request) Close

func (c *Request) Close() error

func (*Request) Command

func (c *Request) Command(cmd string) *Request

func (*Request) Config

func (c *Request) Config(conf Config) *Request

func (*Request) Conn

func (c *Request) Conn(ownership ...bool) net.Conn

if ownership is `true`,the conn is never close! so you need close manual.

func (*Request) Do

func (c *Request) Do(ctx context.Context, body interface{}, hds ...interface{}) error

func (*Request) DoNoRes

func (c *Request) DoNoRes(ctx context.Context, body interface{}, hds ...interface{}) error

func (*Request) ReqHeader

func (c *Request) ReqHeader() *Map

func (*Request) Res

func (c *Request) Res() error

func (*Request) ResBodyBytes

func (c *Request) ResBodyBytes() []byte

func (*Request) ResBodyJson

func (c *Request) ResBodyJson(bd interface{}) error

func (*Request) ResCode

func (c *Request) ResCode() int32

func (*Request) ResHeadBytes

func (c *Request) ResHeadBytes() []byte

func (*Request) ResHeader

func (c *Request) ResHeader() (*Map, error)

func (*Request) SetArg added in v1.0.1

func (c *Request) SetArg(k, v string) *Request

func (*Request) SetContext

func (c *Request) SetContext(ctx context.Context) *Request

func (*Request) Timeout

func (c *Request) Timeout(tmo time.Duration) *Request

type SliceMock

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

Jump to

Keyboard shortcuts

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