Documentation
¶
Overview ¶
channel.go 中转层,框架层与底层交互的管道,负责连接池管理、打包发送、回包转发
Index ¶
- Constants
- func AesDecrypt(passwd, ctx []byte) []byte
- func AesEncrypt(passwd, ctx []byte) []byte
- func Base58Decode(input []byte) []byte
- func Base58Encode(input []byte) []byte
- func Base64Decode(str string) ([]byte, error)
- func Base64Encode(data []byte) string
- func Bytes2Str(b []byte) string
- func BytesToInt(buf []byte) int64
- func CalBasicAuthValue(username, password string) string
- func CheckBasicAuth(w http.ResponseWriter, r *http.Request) (uname string, upass string, bRet bool)
- func CheckKey(key string) (sessid string, uid uint64, e error)
- func CheckPlainKey(key string) (sessid string, uid uint64, e error)
- func CheckSession(sess *Session) (sessid string, uid uint64, e error)
- func ErrStr(eno string) string
- func EscapeByte(w io.Writer, b []byte)
- func FileExists(path string) (bool, error)
- func Fmt2Time(s string) (ret time.Time, err error)
- func Fmt2Ts(s string) int64
- func GenEmailCode() string
- func GenImgCode() string
- func GenKey(sessid, passwd string, uid, expire uint64) string
- func GenSessid(uid uint64) string
- func GetRealIP(r *http.Request) string
- func GetSvrmark(svrname string) string
- func HashTime33(str string) int
- func HmacSha1(data []byte, key []byte) []byte
- func HmacSha1Str(data []byte, key []byte) string
- func HmacSha256(data []byte, key []byte) []byte
- func HmacSha256Str(data []byte, key []byte) string
- func HttpRequest(method, url string, header map[string]string, body []byte) (buf []byte, err error)
- func HttpRequestAndParse(method, url string, header map[string]string, body []byte, val interface{}) (err error)
- func HttpRequestTimeoutAndParse(method, url string, header map[string]string, body []byte, timeout int, ...) (err error)
- func IP2Uint32(ipStr string) uint32
- func If(condition bool, trueVal, falseVal interface{}) interface{}
- func InArray(needle interface{}, hystack interface{}) bool
- func InitLog(logdir string, svrname string, warnstr string, fn func(s string), ...)
- func IntToBytes(num interface{}) []byte
- func JoinArray(arr interface{}, sep string) string
- func JsonData(reqjson interface{}) []byte
- func JsonEncode(s string) string
- func JsonMarshal(v interface{}) (data []byte, err error)
- func JsonUnmarshal(data []byte, v interface{}) (err error)
- func ListenWsServer(addr string, webdir string, chmgr *ChannelManager, ...)
- func LogBool(cond bool, args ...interface{})
- func LogD(format string, v ...interface{})
- func LogError(err error, args ...interface{})
- func LogSetCallback(fn func(s string))
- func LogUid(uid uint64, format string, v ...interface{})
- func LogUpdateLevel(level int, uids []uint64)
- func LogW(format string, v ...interface{})
- func LogWrite(w io.Writer, level string, format string, v ...interface{})
- func LowerCaseWithUnderscores(name string) string
- func Md5(data []byte) []byte
- func Md5Str(data []byte) string
- func NewError(format string, v ...interface{}) error
- func Sha1(data []byte) []byte
- func Sha1Str(data []byte) string
- func StatChg(key string, val int64)
- func StatKeepMax(key string, val int64)
- func StatKeepMin(key string, val int64)
- func StatSet(key string, val int64)
- func Str2Bytes(s string) []byte
- func Str2Time(str, format string) (ret time.Time, err error)
- func StringSlice(ss interface{}) []string
- func Struct2Map(obj interface{}, args ...interface{}) map[string]interface{}
- func TimeNowUnix() int64
- func ToSlice(arr interface{}) ([]interface{}, bool)
- func ToStr(data interface{}) string
- func Ts2Fmt(ts int64) string
- func Uint32ToIP(ip uint32) string
- func UploadHandler(w http.ResponseWriter, r *http.Request, up_path string)
- func UpperCaseWithNoUnderscores(name string) string
- type Channel
- type ChannelManager
- func (cm *ChannelManager) DelChannel(ch *Channel)
- func (cm *ChannelManager) GetChannel(seq uint64) (*Channel, error)
- func (cm *ChannelManager) NewChannel() *Channel
- func (cm *ChannelManager) PushAllChannelMsg(m interface{}, fn func(Data interface{}) bool) error
- func (cm *ChannelManager) PushChannelMsg(seq uint64, m interface{}) error
- func (cm *ChannelManager) PushOneChannelMsg(m interface{}, fn func(Data interface{}) bool) error
- type Error
- type ParaNull
- type ReqCtx
- type ReqCtxHandler
- type RpcError
- type RpcMsg
- func PackError(cmd string, err string, msg string) *RpcMsg
- func PackFatal(msg string) *RpcMsg
- func PackNull(cmd string) *RpcMsg
- func PackPara(cmd string, para interface{}) *RpcMsg
- func PackRpcMsg(cmd string, para interface{}, sess *Session) *RpcMsg
- func PackRspMsg(reqmsg *RpcMsg, eret string, rsp interface{}, eid ...string) (rspmsg *RpcMsg)
- func RpcReturn(reqmsg *RpcMsg, eret_rpcerr interface{}, rsp ...interface{}) (rspmsg *RpcMsg, err error)
- type Session
- type Sqler
- func (dba *Sqler) Avg(avg string) string
- func (dba *Sqler) BuildExecut() (string, error)
- func (dba *Sqler) BuildQuery() (string, error)
- func (dba *Sqler) Count(args ...interface{}) string
- func (dba *Sqler) Delete() string
- func (dba *Sqler) Distinct() *Sqler
- func (dba *Sqler) Group(group string) *Sqler
- func (dba *Sqler) Having(having string) *Sqler
- func (dba *Sqler) Ignore() *Sqler
- func (dba *Sqler) Insert(data interface{}) string
- func (dba *Sqler) InsertBatch(data interface{}) string
- func (dba *Sqler) InsertDuplicate(data interface{}, key_fields []string, args ...interface{}) string
- func (dba *Sqler) Join(args ...interface{}) *Sqler
- func (dba *Sqler) LeftJoin(args ...interface{}) *Sqler
- func (dba *Sqler) Limit(limit int) *Sqler
- func (dba *Sqler) Max(max string) string
- func (dba *Sqler) Min(min string) string
- func (dba *Sqler) Offset(offset int) *Sqler
- func (dba *Sqler) OrIgnore() *Sqler
- func (dba *Sqler) OrWhere(args ...interface{}) *Sqler
- func (dba *Sqler) Order(order string) *Sqler
- func (dba *Sqler) Page(page int) *Sqler
- func (dba *Sqler) Reset()
- func (dba *Sqler) RightJoin(args ...interface{}) *Sqler
- func (dba *Sqler) Select(args ...interface{}) string
- func (dba *Sqler) Sum(sum string) string
- func (dba *Sqler) Table(table string) *Sqler
- func (dba *Sqler) Update(data interface{}, args ...interface{}) string
- func (dba *Sqler) UpdateBatch(data []map[string]interface{}, keyarr interface{}, args ...interface{}) string
- func (dba *Sqler) Where(args ...interface{}) *Sqler
- type TagOptions
- type WebSock
- func (c *WebSock) Close()
- func (c *WebSock) ConnInfo() (s string)
- func (c *WebSock) DefHandleFunc(fn interface{})
- func (c *WebSock) HandleFunc(cmd string, fn interface{})
- func (c *WebSock) HandleFuncMap(mm map[string]ReqCtxHandler)
- func (c *WebSock) IsReady() bool
- func (c *WebSock) OpenCoroutineFlag()
- func (c *WebSock) RecvRequest()
- func (c *WebSock) SendRpc(rpcmsg *RpcMsg) error
- func (c *WebSock) SendRpcParseResponse(rpcmsg *RpcMsg, sec int64, pret interface{}) (err error)
- func (c *WebSock) SendRpcSafe(rpcmsg *RpcMsg) error
- func (c *WebSock) SendRpcWithResponse(rpcmsg *RpcMsg, sec int64) (rsp *RpcMsg, err error)
- func (c *WebSock) SetCloseHandler(handler func(c *WebSock))
- func (c *WebSock) SetIntervalHandler(fn func(c *WebSock, ms int64))
- func (c *WebSock) SetOpenHandler(handler func(c *WebSock))
- func (c *WebSock) SetReadTimeout(read_timeo int64)
- func (c *WebSock) SkipHandleFunc(cmd string)
- func (c *WebSock) StartDial(chk_interval int64, def_ip string)
- type WsHandler
Constants ¶
View Source
const ( DATE_FMT_STR = "2006-01-02" DATE_TIME_FMT_STR = "2006-01-02 15:04:05" )
View Source
const EBADGATEWAY = "EBADGATEWAY"
View Source
const EBALANCE = "EBALANCE"
View Source
const EEXISTS = "EEXISTS"
View Source
const EFATAL = "EFATAL"
View Source
const ELIMITED = "ELIMITED"
View Source
const ENEEDCODE = "ENEEDCODE"
View Source
const ENEXISTS = "ENEXISTS"
View Source
const ENODATA = "ENODATA"
View Source
const ENOTALLOW = "ENOTALLOW"
View Source
const ENOTAUTH = "ENOTAUTH"
View Source
const ENOTPERM = "ENOTPERM"
View Source
const EPARAM = "EPARAM"
View Source
const EPASSWD = "EPASSWD"
View Source
const ESERVER = "ESERVER"
View Source
const ESUCC = "ESUCC"
外部错误号
View Source
const ETIMENOTALLOW = "ETIMENOTALLOW"
View Source
const ETIMEOUT = "ETIMEOUT"
Variables ¶
This section is empty.
Functions ¶
func AesDecrypt ¶
func Base58Encode ¶
Base58Encode encodes a byte array to Base58
func CalBasicAuthValue ¶
func CheckBasicAuth ¶
func EscapeByte ¶
func FileExists ¶
func GenEmailCode ¶
func GenEmailCode() string
func GenImgCode ¶
func GenImgCode() string
func GetSvrmark ¶
func HttpRequest ¶
func HttpRequestAndParse ¶
func If ¶
func If(condition bool, trueVal, falseVal interface{}) interface{}
If : ternary operator (三元运算) condition:比较运算 trueVal:运算结果为真时的值 falseVal:运算结果为假时的值 return: 由于不知道传入值的类型, 所有, 必须在接收结果时, 指定对应的值类型
func JsonEncode ¶
func JsonMarshal ¶
func JsonUnmarshal ¶
func ListenWsServer ¶
func ListenWsServer(addr string, webdir string, chmgr *ChannelManager, open_fn func(http.ResponseWriter, *http.Request, *WebSock) error)
func LogSetCallback ¶
func LogSetCallback(fn func(s string))
func LogUpdateLevel ¶
func LowerCaseWithUnderscores ¶
映射函数:首字母转小写,大写转成下划线加小写 反向则是:首字母大写,下划线去掉,其后字母转大写
func StatKeepMax ¶
func StatKeepMin ¶
func StringSlice ¶
func StringSlice(ss interface{}) []string
func Struct2Map ¶
func Struct2Map(obj interface{}, args ...interface{}) map[string]interface{}
func TimeNowUnix ¶
func TimeNowUnix() int64
func UploadHandler ¶
func UploadHandler(w http.ResponseWriter, r *http.Request, up_path string)
Types ¶
type Channel ¶
type Channel struct {
Data interface{}
Chmgr *ChannelManager
// contains filtered or unexported fields
}
type ChannelManager ¶
type ChannelManager struct {
// contains filtered or unexported fields
}
func NewChannelManager ¶
func NewChannelManager(chlen uint64) *ChannelManager
func (*ChannelManager) DelChannel ¶
func (cm *ChannelManager) DelChannel(ch *Channel)
func (*ChannelManager) GetChannel ¶
func (cm *ChannelManager) GetChannel(seq uint64) (*Channel, error)
func (*ChannelManager) NewChannel ¶
func (cm *ChannelManager) NewChannel() *Channel
func (*ChannelManager) PushAllChannelMsg ¶
func (cm *ChannelManager) PushAllChannelMsg(m interface{}, fn func(Data interface{}) bool) error
func (*ChannelManager) PushChannelMsg ¶
func (cm *ChannelManager) PushChannelMsg(seq uint64, m interface{}) error
func (*ChannelManager) PushOneChannelMsg ¶
func (cm *ChannelManager) PushOneChannelMsg(m interface{}, fn func(Data interface{}) bool) error
type Error ¶
type ReqCtx ¶
type ReqCtx = struct {
Ctx interface{} // 所在环境,例如websock, ns, ...
Cmd string // 原请求命令,例如logind.registe
Sess *Session // 请求环境
CoSche bool // 是否在新起协程环境?方便判断堵塞情况
}
func MakeReqCtx ¶
type RpcError ¶
func NewRpcError ¶
type RpcMsg ¶
type RpcMsg = struct {
Cmd string `json:"cmd,omitempty"`
Mark string `json:"mark,omitempty"` // 标志,通常用于细化转发
Chk string `json:"chk,omitempty"`
Sess *Session `json:"sess,omitempty"`
Err *Error `json:"err,omitempty"`
Para json.RawMessage `json:"para,omitempty"`
}
func PackRpcMsg ¶
func PackRspMsg ¶
type Session ¶
type Sqler ¶
type Sqler struct {
// contains filtered or unexported fields
}
Sqler is data mapper struct
func (*Sqler) BuildExecut ¶
BuildExecut : build execute query string
func (*Sqler) BuildQuery ¶
BuildQuery : build query string
func (*Sqler) InsertBatch ¶
func (*Sqler) InsertDuplicate ¶
func (*Sqler) Reset ¶
func (dba *Sqler) Reset()
------------------------------------------------------------------------- Reset : reset union select
func (*Sqler) UpdateBatch ¶
type TagOptions ¶
func GetTagOptions ¶
func GetTagOptions(tag reflect.StructTag, tagname string) TagOptions
type WebSock ¶
type WebSock struct {
Ws *websocket.Conn
Ch *Channel
Data interface{} // 用于扩展
Sess *Session // 一般是在open_fn里设置好这里,方便后面makereqctx
// contains filtered or unexported fields
}
func InitWebSock ¶
func InitWebSock(w http.ResponseWriter, r *http.Request, chmgr *ChannelManager) (c *WebSock, err error)
func InitWsClient ¶
func (*WebSock) DefHandleFunc ¶
func (c *WebSock) DefHandleFunc(fn interface{})
func (*WebSock) HandleFuncMap ¶
func (c *WebSock) HandleFuncMap(mm map[string]ReqCtxHandler)
func (*WebSock) OpenCoroutineFlag ¶
func (c *WebSock) OpenCoroutineFlag()
func (*WebSock) SendRpcParseResponse ¶
func (*WebSock) SendRpcSafe ¶
func (*WebSock) SendRpcWithResponse ¶
func (*WebSock) SetCloseHandler ¶
func (*WebSock) SetIntervalHandler ¶
func (*WebSock) SetOpenHandler ¶
func (*WebSock) SetReadTimeout ¶
func (*WebSock) SkipHandleFunc ¶
Click to show internal directories.
Click to hide internal directories.