Documentation ¶
Index ¶
- Constants
- Variables
- func AddStopCheck(cs string) uint64
- func Atoi(str string) int
- func CmdAct(cmd, act uint8) int
- func ContainsStr(s, substr string) bool
- func DBData(v proto.Message) []byte
- func DBStr(v proto.Message) string
- func Daemon(skip ...string)
- func Date() string
- func Debug(args ...interface{})
- func DebugRoutineEndStack(id uint64, count int64)
- func DebugRoutineStartStack(id uint64, count int64)
- func Debugf(format string, args ...interface{})
- func DelDir(path string)
- func DelFile(path string)
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func FindStr(s string, f string) int
- func GetErrID(err error) uint16
- func GetError(id uint16) error
- func GetFiles(path string) []string
- func GetHour(timestamp int64, timezone int) int
- func GetHour23(timestamp int64, timezone int) int
- func GetHour24(timestamp int64, timezone int) int
- func GetNextHourIntervalMS(timestamp int64) int
- func GetNextHourIntervalS(timestamp int64) int
- func GetSelfExtraIP(ifNames ...string) (ips []string)
- func GetSelfIP(ifNames ...string) []string
- func GetSelfIntraIP(ifNames ...string) (ips []string)
- func Go(fn func())
- func Go2(fn func(stopCh chan struct{})) bool
- func GoArgs(fn func(...interface{}), args ...interface{})
- func HTTPGet(url string) (string, *http.Response, error)
- func HTTPGetWithBasicAuth(url, name, passwd string) (string, *http.Response, error)
- func HTTPPost(url, form string) (string, *http.Response, error)
- func HTTPUpload(url, field, file string) (*http.Response, error)
- func HookLogger(in Logger)
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func IsDiffDay(now, old int64, timezone int) int
- func IsDiffHour(now, old int64, hour, timezone int) bool
- func IsDiffWeek(now, old int64, hour, timezone int) bool
- func IsRunning() bool
- func IsStop() bool
- func Itoa(num interface{}) string
- func JSONPack(msg interface{}) ([]byte, error)
- func JSONUnPack(data []byte, msg interface{}) error
- func JoinStr(a []string, sep string) string
- func LogStack()
- func MsgPackPack(msg interface{}) ([]byte, error)
- func MsgPackUnPack(data []byte, msg interface{}) error
- func NewDir(path string) error
- func NewRedisScript(commit, str string) int
- func Now() time.Time
- func PBPack(msg interface{}) ([]byte, error)
- func PBUnPack(data []byte, msg interface{}) error
- func Panic(args ...interface{})
- func Panicf(format string, args ...interface{})
- func ParseBaseKind(kind reflect.Kind, data string) (interface{}, error)
- func ParseDBData(data []byte, v proto.Message) bool
- func ParseDBStr(str string, v proto.Message) bool
- func ParsePbData(data []byte, v proto.Message) bool
- func ParsePbStr(str string, v proto.Message) bool
- func ParseTime(str string) (time.Time, error)
- func PathBase(p string) string
- func PathClean(p string) string
- func PathDir(p string) string
- func PathExists(path string) bool
- func PathExt(p string) string
- func PbData(v proto.Message) []byte
- func PbStr(v proto.Message) string
- func Print(a ...interface{}) (int, error)
- func Printf(format string, a ...interface{}) (int, error)
- func Println(a ...interface{}) (int, error)
- func ReadFile(path string) ([]byte, error)
- func RedisError(err error) bool
- func RemoveStopCheck(id uint64)
- func ReplaceStr(s, old, new string) string
- func SendMail(user, password, host, to, subject, body, mailtype string) error
- func SetTimeout(interval int, fn func(...interface{}) int, args ...interface{})
- func Sleep(ms int)
- func SplitStr(s string, sep string) []string
- func SplitStrN(s string, sep string, n int) []string
- func Sprintf(format string, a ...interface{}) string
- func StartServer(addr string, typ MsgType, handler IMsgHandler, parser *Parser) error
- func Stop()
- func StrContains(s, substr string) bool
- func StrFind(s string, f string) int
- func StrJoin(a []string, sep string) string
- func StrReplace(s, old, new string) string
- func StrSplit(s string, sep string) []string
- func StrSplitN(s string, sep string, n int) []string
- func StrToLower(s string) string
- func StrToUpper(s string) string
- func StrTrim(s string) string
- func StrTrimRight(s, cutset string) string
- func Tag(cmd, act uint8, index uint16) int
- func ToLowerStr(s string) string
- func ToUpperStr(s string) string
- func TrimRightStr(s, cutset string) string
- func TrimStr(s string) string
- func Try(fun func(), handler func(interface{}))
- func UnixMs() int64
- func UnixTime(sec, nsec int64) time.Time
- func WaitForSystemExit(atexit ...func())
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- func WriteFile(path string, data []byte)
- type CmdMatchType
- type ConnType
- type DefMsgHandler
- func (r *DefMsgHandler) GetHandlerFunc(msgQue IMsgQue, msg *Message) HandlerFunc
- func (r *DefMsgHandler) OnConnectComplete(msgQue IMsgQue, ok bool) bool
- func (r *DefMsgHandler) OnDelMsgQue(msgQue IMsgQue)
- func (r *DefMsgHandler) OnNewMsgQue(msgQue IMsgQue) bool
- func (r *DefMsgHandler) OnProcessMsg(msgQue IMsgQue, msg *Message) bool
- func (r *DefMsgHandler) Register(cmd, act uint8, fun HandlerFunc)
- func (r *DefMsgHandler) RegisterMsg(v interface{}, fun HandlerFunc)
- type EchoMsgHandler
- type Errorz
- type HandlerFunc
- type IMsgHandler
- type IMsgParser
- type IMsgQue
- type IMsgRegister
- type IParser
- type Logger
- type Message
- func NewDataMsg(data []byte) *Message
- func NewErrMsg(err error) *Message
- func NewForverMsg(cmd, act uint8, index, err uint16, data []byte) *Message
- func NewMsg(cmd, act uint8, index, err uint16, data []byte) *Message
- func NewStrMsg(str string) *Message
- func NewTagMsg(cmd, act uint8, index uint16) *Message
- type MessageHead
- type MsgParser
- type MsgType
- type NetType
- type ParseErrType
- type ParseFunc
- type Parser
- func (r *Parser) Get() IParser
- func (r *Parser) GetErrType() ParseErrType
- func (r *Parser) GetType() ParserType
- func (r *Parser) Register(cmd, act uint8, c2s interface{}, s2c interface{})
- func (r *Parser) RegisterFunc(cmd, act uint8, c2sFunc ParseFunc, s2cFunc ParseFunc)
- func (r *Parser) RegisterMsg(c2s interface{}, s2c interface{})
- func (r *Parser) RegisterMsgFunc(c2sFunc ParseFunc, s2cFunc ParseFunc)
- type ParserType
- type Redis
- func (r *Redis) Script(cmd int, keys []string, args ...interface{}) (interface{}, error)
- func (r *Redis) ScriptInt64(cmd int, keys []string, args ...interface{}) (int64, error)
- func (r *Redis) ScriptStr(cmd int, keys []string, args ...interface{}) (string, error)
- func (r *Redis) ScriptStrArray(cmd int, keys []string, args ...interface{}) ([]string, error)
- type RedisConfig
- type RedisManager
- type RedisModel
- func (r *RedisModel) DBData(v proto.Message) []byte
- func (r *RedisModel) DBStr(v proto.Message) string
- func (r *RedisModel) ParseDBData(data []byte, v proto.Message) bool
- func (r *RedisModel) ParseDBStr(str string, v proto.Message) bool
- func (r *RedisModel) ParsePbData(data []byte, v proto.Message) bool
- func (r *RedisModel) ParsePbStr(str string, v proto.Message) bool
- func (r *RedisModel) PbData(v proto.Message) []byte
- type Stat
- type StopCheckMap
- type WaitGroup
Constants ¶
View Source
const ( FlagEncrypt = 1 << 0 //encrypted data FlagCompress = 1 << 1 //compressed data FlagContinue = 1 << 2 //still have remain data need to be received FlagNeedAck = 1 << 3 //message should be acknowledged FlagAck = 1 << 4 //acknowledgement message FlagReSend = 1 << 5 //message been re-sent FlagClient = 1 << 6 //use this to tell the message source, internal server or published client )
View Source
const (
MsgHeadSize = 12
)
Variables ¶
View Source
var ( ErrOk = NewError("success", 0) ErrPBPack = NewError("pb pack error", 1) ErrPBUnPack = NewError("pb unpack error", 2) ErrJSONPack = NewError("json pack error", 3) ErrJSONUnPack = NewError("json unpack error", 4) ErrCmdUnPack = NewError("cmd parse error", 5) ErrMsgLenTooLong = NewError("message too long", 6) ErrMsgLenTooShort = NewError("message too short", 7) ErrDBDataType = NewError("bad db type", 8) ErrErrIDNotFound = NewError("unknown error code", 255) )
View Source
var DefMsgQueTimeout = 180
View Source
var ErrIDMap = map[error]uint16{}
View Source
var IDErrMap = map[uint16]error{}
View Source
var MaxMsgDataSize uint32 = 1024 * 1024
View Source
var MinUserError = 256
View Source
var NowTick int64
View Source
var StartTick int64
View Source
var Timestamp int64
View Source
var UDPServerGoCnt = 32
Functions ¶
func AddStopCheck ¶
func ContainsStr ¶
func DebugRoutineEndStack ¶
func DebugRoutineStartStack ¶
func GetNextHourIntervalMS ¶
func GetNextHourIntervalS ¶
func GetSelfExtraIP ¶
func GetSelfIntraIP ¶
func HTTPGetWithBasicAuth ¶
func HookLogger ¶
func HookLogger(in Logger)
func IsDiffHour ¶
func IsDiffWeek ¶
func JSONUnPack ¶
func MsgPackPack ¶
func MsgPackUnPack ¶
func NewRedisScript ¶
func PathExists ¶
func RedisError ¶
func RemoveStopCheck ¶
func RemoveStopCheck(id uint64)
func ReplaceStr ¶
func SetTimeout ¶
func StartServer ¶
func StartServer(addr string, typ MsgType, handler IMsgHandler, parser *Parser) error
func StrContains ¶
func StrReplace ¶
func StrToLower ¶
func StrToUpper ¶
func StrTrimRight ¶
func ToLowerStr ¶
func ToUpperStr ¶
func TrimRightStr ¶
func WaitForSystemExit ¶
func WaitForSystemExit(atexit ...func())
Types ¶
type CmdMatchType ¶
type CmdMatchType int
const ( CmdMatchTypeK CmdMatchType = iota CmdMatchTypeKV )
type DefMsgHandler ¶
type DefMsgHandler struct {
// contains filtered or unexported fields
}
func (*DefMsgHandler) GetHandlerFunc ¶
func (r *DefMsgHandler) GetHandlerFunc(msgQue IMsgQue, msg *Message) HandlerFunc
func (*DefMsgHandler) OnConnectComplete ¶
func (r *DefMsgHandler) OnConnectComplete(msgQue IMsgQue, ok bool) bool
func (*DefMsgHandler) OnDelMsgQue ¶
func (r *DefMsgHandler) OnDelMsgQue(msgQue IMsgQue)
func (*DefMsgHandler) OnNewMsgQue ¶
func (r *DefMsgHandler) OnNewMsgQue(msgQue IMsgQue) bool
func (*DefMsgHandler) OnProcessMsg ¶
func (r *DefMsgHandler) OnProcessMsg(msgQue IMsgQue, msg *Message) bool
func (*DefMsgHandler) Register ¶
func (r *DefMsgHandler) Register(cmd, act uint8, fun HandlerFunc)
func (*DefMsgHandler) RegisterMsg ¶
func (r *DefMsgHandler) RegisterMsg(v interface{}, fun HandlerFunc)
type EchoMsgHandler ¶
type EchoMsgHandler struct {
DefMsgHandler
}
func (*EchoMsgHandler) OnProcessMsg ¶
func (r *EchoMsgHandler) OnProcessMsg(msgQue IMsgQue, msg *Message) bool
type HandlerFunc ¶
type IMsgHandler ¶
type IMsgParser ¶
type IMsgQue ¶
type IMsgQue interface { ID() uint32 GetMsgType() MsgType GetConnType() ConnType GetNetType() NetType LocalAddr() string RemoteAddr() string Stop() IsStop() bool Available() bool Send(m *Message) (re bool) SendString(str string) (re bool) SendStringLn(str string) (re bool) SendByteStr(str []byte) (re bool) SendByteStrLn(str []byte) (re bool) SendCallback(m *Message, c chan *Message) (re bool) SetTimeout(t int) GetTimeout() int Reconnect(t int) //reconnect interval, unit: s, this function only can be invoked when connection was closed GetHandler() IMsgHandler SetUser(user interface{}) GetUser() interface{} SetExtData(extData interface{}) GetExtData() interface{} // contains filtered or unexported methods }
func StartConnect ¶
type IMsgRegister ¶
type IMsgRegister interface { Register(cmd, act uint8, fun HandlerFunc) RegisterMsg(v interface{}, fun HandlerFunc) }
type IParser ¶
type IParser interface { GetType() ParserType GetErrType() ParseErrType ParseC2S(msg *Message) (IMsgParser, error) PackMsg(v interface{}) []byte GetRemindMsg(err error, t MsgType) *Message }
type Logger ¶
type Logger interface { Debug(args ...interface{}) Info(args ...interface{}) Warn(args ...interface{}) Error(args ...interface{}) Panic(args ...interface{}) Fatal(args ...interface{}) Debugf(format string, args ...interface{}) Infof(format string, args ...interface{}) Warnf(format string, args ...interface{}) Errorf(format string, args ...interface{}) Panicf(format string, args ...interface{}) Fatalf(format string, args ...interface{}) }
type Message ¶
type Message struct { Head *MessageHead //message head, can be empty Data []byte //message data IMsgParser //message parser User interface{} //user self defined data }
func NewDataMsg ¶
type MessageHead ¶
type MessageHead struct { Len uint32 Error uint16 Cmd uint8 Act uint8 Index uint16 Flags uint16 // contains filtered or unexported fields }
func MessageHeadFromByte ¶
func MessageHeadFromByte(data []byte) *MessageHead
func NewMessageHead ¶
func NewMessageHead(data []byte) *MessageHead
func (*MessageHead) Bytes ¶
func (r *MessageHead) Bytes() []byte
func (*MessageHead) BytesWithData ¶
func (r *MessageHead) BytesWithData(wdata []byte) []byte
func (*MessageHead) CmdAct ¶
func (r *MessageHead) CmdAct() int
func (*MessageHead) FromBytes ¶
func (r *MessageHead) FromBytes(data []byte) error
func (*MessageHead) String ¶
func (r *MessageHead) String() string
func (*MessageHead) Tag ¶
func (r *MessageHead) Tag() int
type ParseErrType ¶
type ParseErrType int
const ( ParseErrTypeSendRemind ParseErrType = iota // if message parsed failed, send message tips to sender, notice sender message send failed ParseErrTypeContinue // if message parsed failed, skip this message ParseErrTypeAlways // if message parsed failed, still go to nex logic ParseErrTypeClose // if message parsed failed, closed connection )
type Parser ¶
type Parser struct { Type ParserType ErrType ParseErrType // contains filtered or unexported fields }
func (*Parser) GetErrType ¶
func (r *Parser) GetErrType() ParseErrType
func (*Parser) GetType ¶
func (r *Parser) GetType() ParserType
func (*Parser) RegisterFunc ¶
func (*Parser) RegisterMsg ¶
func (r *Parser) RegisterMsg(c2s interface{}, s2c interface{})
func (*Parser) RegisterMsgFunc ¶
type ParserType ¶
type ParserType int
const ( ParserTypePB ParserType = iota // protoBuf, use this type of message to communicate with client ParserTypeJSON // json type ParserTypeCmd // cmd type, like telnet, console ParserTypeRaw // do not parse whatever )
type RedisConfig ¶
type RedisManager ¶
type RedisManager struct {
// contains filtered or unexported fields
}
func NewRedisManager ¶
func NewRedisManager(conf *RedisConfig) *RedisManager
func (*RedisManager) Add ¶
func (r *RedisManager) Add(id int, conf *RedisConfig)
func (*RedisManager) Exist ¶
func (r *RedisManager) Exist(id int) bool
func (*RedisManager) GetByRid ¶
func (r *RedisManager) GetByRid(rid int) *Redis
func (*RedisManager) GetGlobal ¶
func (r *RedisManager) GetGlobal() *Redis
func (*RedisManager) Sub ¶
func (r *RedisManager) Sub(fun func(channel, data string), channels ...string)
type RedisModel ¶
type RedisModel struct{}
func (*RedisModel) ParseDBData ¶
func (r *RedisModel) ParseDBData(data []byte, v proto.Message) bool
func (*RedisModel) ParseDBStr ¶
func (r *RedisModel) ParseDBStr(str string, v proto.Message) bool
func (*RedisModel) ParsePbData ¶
func (r *RedisModel) ParsePbData(data []byte, v proto.Message) bool
func (*RedisModel) ParsePbStr ¶
func (r *RedisModel) ParsePbStr(str string, v proto.Message) bool
Click to show internal directories.
Click to hide internal directories.