iotconn

package module
v0.0.0-...-bb7f942 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

README

IotConn

介绍

轻量级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       = 1
	ResStatusErr      = 2
	ResStatusAuth     = 3
	ResStatusNotFound = 4
)

Variables

This section is empty.

Functions

func ReadBodyTimeout

func ReadBodyTimeout(n time.Duration)

func ReadHeadTimeout

func ReadHeadTimeout(n time.Duration)

func SetMaxBodyLen

func SetMaxBodyLen(n uint)

func SetMaxHeadLen

func SetMaxHeadLen(n uint)

Types

type AuthFun

type AuthFun = func(c *Context) bool

type ConnFun

type ConnFun func(res *Context)

返回true则连接不会关闭

func ParamFunHandle

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

func RPCFunHandle

func RPCFunHandle(t interface{}, authfn ...AuthFun) ConnFun

type Context

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

func (*Context) BodyBytes

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

func (*Context) GetConn

func (c *Context) GetConn() net.Conn

func (*Context) HeadBytes

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

func (*Context) ReqHeader

func (c *Context) ReqHeader() (*Header, error)

func (*Context) ResBytes

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

func (*Context) ResHeader

func (c *Context) ResHeader() *Header

func (*Context) ResJson

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

func (*Context) ResString

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

type Engine

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

func NewEngine

func NewEngine(ctx context.Context) *Engine

func (*Engine) ReadBodyTimeout

func (c *Engine) ReadBodyTimeout(n time.Duration)

func (*Engine) ReadHeadTimeout

func (c *Engine) ReadHeadTimeout(n time.Duration)

func (*Engine) RegFun

func (c *Engine) RegFun(mcode int, fn ConnFun) bool

func (*Engine) Run

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

func (*Engine) SetMaxBodyLen

func (c *Engine) SetMaxBodyLen(n uint)

func (*Engine) SetMaxHeadLen

func (c *Engine) SetMaxHeadLen(n uint)
type Header struct {
	Path  string `json:"path"`
	RelIp string `json:"ip"`    // 真实IP
	Token string `json:"token"` // 请求token
	Times string `json:"times"` // 请求时间

	Info map[string]interface{} `json:"info"`
}

func ParseHeader

func ParseHeader(bts []byte) (*Header, error)

func (*Header) Bytes

func (c *Header) Bytes() []byte

func (*Header) Del

func (c *Header) Del(key string)

func (*Header) Get

func (c *Header) Get(key string) (interface{}, bool)

func (*Header) GetBool

func (c *Header) GetBool(key string) bool

func (*Header) GetFloat

func (c *Header) GetFloat(key string) (float64, error)

func (*Header) GetInt

func (c *Header) GetInt(key string) (int64, error)

func (*Header) GetString

func (c *Header) GetString(key string) (string, bool)

func (*Header) Set

func (c *Header) Set(key string, val interface{})

type Mp

type Mp map[string]interface{}

type Request

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

func NewRPCReq

func NewRPCReq(addr string, path string, timeout ...time.Duration) (*Request, error)

func NewRequest

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

func (*Request) Close

func (c *Request) Close() error

func (*Request) Do

func (c *Request) Do(control int, body interface{}, hds ...[]byte) error

func (*Request) GetConn

func (c *Request) GetConn() net.Conn

func (*Request) ReqHeader

func (c *Request) ReqHeader() *Header

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() int

func (*Request) ResHeadBytes

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

func (*Request) ResHeader

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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