antnet: github.com/magiclvzs/antnet Index | Files

package antnet

import "github.com/magiclvzs/antnet"

模型来自pb //特别注意,lua只至此double,int64的数据如果进行cmsgpack打包解包可能出现精度问题导致bug

Index

Package Files

config_csv.go config_json.go container.go db_redis.go error.go func.go func_compress.go func_file.go func_fmt.go func_go.go func_net.go func_strings.go init.go log.go math.go model_redis.go msgque.go msgque_msg.go msgque_tcp.go msgque_udp.go msgque_ws.go parser.go parser_cmd.go parser_json.go parser_msgpack.go parser_pb.go time.go

Constants

const (
    FlagEncrypt  = 1 << 0 //数据是经过加密的
    FlagCompress = 1 << 1 //数据是经过压缩的
    FlagContinue = 1 << 2 //消息还有后续
    FlagNeedAck  = 1 << 3 //消息需要确认
    FlagAck      = 1 << 4 //确认消息
    FlagReSend   = 1 << 5 //重发消息
    FlagClient   = 1 << 6 //消息来自客服端,用于判断index来之服务器还是其他玩家
)
const (
    MsgHeadSize = 12
)

Variables

var (
    ErrOk             = NewError("正确", 0)
    ErrDBErr          = NewError("数据库错误", 1)
    ErrProtoPack      = NewError("协议解析错误", 2)
    ErrProtoUnPack    = NewError("协议打包错误", 3)
    ErrMsgPackPack    = NewError("msgpack打包错误", 4)
    ErrMsgPackUnPack  = NewError("msgpack解析错误", 5)
    ErrPBPack         = NewError("pb打包错误", 6)
    ErrPBUnPack       = NewError("pb解析错误", 7)
    ErrJsonPack       = NewError("json打包错误", 8)
    ErrJsonUnPack     = NewError("json解析错误", 9)
    ErrCmdUnPack      = NewError("cmd解析错误", 10)
    ErrMsgLenTooLong  = NewError("数据过长", 11)
    ErrMsgLenTooShort = NewError("数据过短", 12)
    ErrHttpRequest    = NewError("http请求错误", 13)
    ErrCSVParse       = NewError("csv解析错误", 14)
    ErrGobPack        = NewError("gob打包错误", 15)
    ErrGobUnPack      = NewError("gob解析错误", 16)
    ErrServePanic     = NewError("服务器内部错误", 17)
    ErrNeedIntraNet   = NewError("需要内网环境", 18)
    ErrConfigPath     = NewError("配置路径错误", 50)

    ErrFileRead       = NewError("文件读取错误", 100)
    ErrDBDataType     = NewError("数据库数据类型错误", 101)
    ErrNetTimeout     = NewError("网络超时", 200)
    ErrNetUnreachable = NewError("网络不可达", 201)

    ErrErrIdNotFound = NewError("错误没有对应的错误码", 255)
)
var Config = struct {
    AutoCompressLen  uint32
    UdpServerGoCnt   int
    TimeSyncInterval uint
    PoolSize         int32
    SSLCrtPath       string
    SSLKeyPath       string
    EnableWss        bool
    ReadDataBuffer   int
    StopTimeout      int
}{UdpServerGoCnt: 64, TimeSyncInterval: 10, PoolSize: 50000, ReadDataBuffer: 1 << 12, StopTimeout: 3000}
var DefMsgQueTimeout int = 180
var LogLevelNameMap = map[string]LogLevel{
    "debug": LogLevelDebug,
    "info":  LogLevelInfo,
    "warn":  LogLevelWarn,
    "error": LogLevelError,
    "fatal": LogLevelFatal,
    "off":   LogLevelAllOff,
}
var MaxMsgDataSize uint32 = 1024 * 1024
var MinUserError = 256
var NowTick int64
var StartTick int64
var Timestamp int64

func Abs Uses

func Abs(x float64) float64

abs

func AddStopCheck Uses

func AddStopCheck(cs string) uint64

func After Uses

func After(ms int) <-chan time.Time

func AtExit Uses

func AtExit(fun func())

func Atof Uses

func Atof(str string) float32

func Atof64 Uses

func Atof64(str string) float64

func Atoi Uses

func Atoi(str string) int

func Atoi64 Uses

func Atoi64(str string) int64

func CmdAct Uses

func CmdAct(cmd, act uint8) int

func ContainsStr Uses

func ContainsStr(s, substr string) bool

func CopyFile Uses

func CopyFile(dst io.Writer, src io.Reader) (written int64, err error)

func CreateFile Uses

func CreateFile(path string) (*os.File, error)

func DBData Uses

func DBData(v proto.Message) []byte

func DBStr Uses

func DBStr(v proto.Message) string

func Daemon Uses

func Daemon(skip ...string)

func Date Uses

func Date() string

func DelDir Uses

func DelDir(path string)

func DelFile Uses

func DelFile(path string)

func DirCount Uses

func DirCount(dir string) int32

func DirSize Uses

func DirSize(dir string) int64

func FileCount Uses

func FileCount(dir string) int32

func FindStr Uses

func FindStr(s string, f string) int

func GZipCompress Uses

func GZipCompress(data []byte) []byte

func GZipUnCompress Uses

func GZipUnCompress(data []byte) ([]byte, error)

func GetCSVParseFunc Uses

func GetCSVParseFunc(kind reflect.Kind) func(fieldv reflect.Value, data, path string) error

func GetEXEDir Uses

func GetEXEDir() string

func GetEXEName Uses

func GetEXEName() string

func GetEXEPath Uses

func GetEXEPath() string

func GetErrId Uses

func GetErrId(err error) uint16

func GetErrJsonData Uses

func GetErrJsonData(err error) []byte

func GetErrJsonStr Uses

func GetErrJsonStr(err error) string

func GetExeDir Uses

func GetExeDir() string

func GetExeName Uses

func GetExeName() string

func GetExePath Uses

func GetExePath() string

func GetFiles Uses

func GetFiles(path string) []string

func GetHour Uses

func GetHour(timestamp int64, timezone int) int

func GetHour23 Uses

func GetHour23(timestamp int64, timezone int) int

*

* @brief 时间戳转换为小时,24小时制,0点用0表示
*
* @param timestamp 时间戳
* @param timezone  时区
* @return uint32_t 小时 范围 0-23

func GetHour24 Uses

func GetHour24(timestamp int64, timezone int) int

* * @brief 时间戳转换为小时,24小时制,0点用24表示 * * @param timestamp 时间戳 * @param timezone 时区 * @return uint32_t 小时 范围 1-24

func GetNextHourIntervalMS Uses

func GetNextHourIntervalMS() int

*

* @brief 获得timestamp距离下个小时的时间,单位ms
*
* @return uint32_t 距离下个小时的时间,单位ms

func GetNextHourIntervalS Uses

func GetNextHourIntervalS() int

* * @brief 获得timestamp距离下个小时的时间,单位s * * @return uint32_t 距离下个小时的时间,单位s

func GetRedisScript Uses

func GetRedisScript(cmd int) string

func GetSelfExtraIp Uses

func GetSelfExtraIp(ifnames ...string) (ips []string)

func GetSelfIntraIp Uses

func GetSelfIntraIp(ifnames ...string) (ips []string)

func GetSelfIp Uses

func GetSelfIp(ifnames ...string) []string

func Go Uses

func Go(fn func())

func Go2 Uses

func Go2(fn func(cstop chan struct{}))

func GoArgs Uses

func GoArgs(fn func(...interface{}), args ...interface{})

func GobPack Uses

func GobPack(e interface{}) ([]byte, error)

func GobUnPack Uses

func GobUnPack(data []byte, msg interface{}) error

func HttpGet Uses

func HttpGet(url string) (string, error, *http.Response)

func HttpGetWithBasicAuth Uses

func HttpGetWithBasicAuth(url, name, passwd string) (string, error, *http.Response)

func HttpPost Uses

func HttpPost(url, form string) (string, error, *http.Response)

func HttpUpload Uses

func HttpUpload(url, field, file string) (*http.Response, error)

func IPCanUse Uses

func IPCanUse(ip string) bool

func IsBetweenHour Uses

func IsBetweenHour(now int64, hour_start, hour_end int, timezone int) bool

* * @brief 判断时间戳是否处于两个小时之内 * * @param now 需要比较的时间戳 * @param hour_start 起始的小时 0 -23 * @param hour_end 结束的小时 0 -23 * @param timezone 时区 * @return bool true表示处于两个小时之间

func IsDiffDay Uses

func IsDiffDay(now, old int64, timezone int) int

* * @brief 判断两个时间戳是否是同一天 * * @param now 需要比较的时间戳 * @param old 需要比较的时间戳 * @param timezone 时区 * @return uint32_t 返回不同的天数

func IsDiffHour Uses

func IsDiffHour(now, old int64, hour, timezone int) bool

* * @brief 判断时间戳是否处于一个小时的两边,即一个时间错大于当前的hour,一个小于 * * @param now 需要比较的时间戳 * @param old 需要比较的时间戳 * @param hour 小时,0-23 * @param timezone 时区 * @return bool true表示时间戳是否处于一个小时的两边

func IsDiffWeek Uses

func IsDiffWeek(now, old int64, hour, timezone int) bool

* * @brief 判断时间戳是否处于跨周, 在周一跨天节点的两边 * * @param now 需要比较的时间戳 * @param old 需要比较的时间戳 * @param hour 小时,0-23 * @param timezone 时区 * @return bool true表示时间戳是否处于跨周, 在周一跨天节点的两边

func IsIntraIp Uses

func IsIntraIp(ip string) bool

func IsRuning Uses

func IsRuning() bool

func IsStop Uses

func IsStop() bool

func Itoa Uses

func Itoa(num interface{}) string

func JoinStr Uses

func JoinStr(a []string, sep string) string

func JsonPack Uses

func JsonPack(msg interface{}) ([]byte, error)

func JsonUnPack Uses

func JsonUnPack(data []byte, msg interface{}) error

func Log10 Uses

func Log10(x float64) float64

Log10为底x的对数

func LogDebug Uses

func LogDebug(v ...interface{})

func LogError Uses

func LogError(v ...interface{})

func LogFatal Uses

func LogFatal(v ...interface{})

func LogInfo Uses

func LogInfo(v ...interface{})

func LogSimpleStack Uses

func LogSimpleStack() string

func LogStack Uses

func LogStack()

func LogWarn Uses

func LogWarn(v ...interface{})

func MD5Bytes Uses

func MD5Bytes(s []byte) string

func MD5File Uses

func MD5File(path string) string

func MD5Str Uses

func MD5Str(s string) string

func MaxInt32 Uses

func MaxInt32() int32

int32

func MsgPackPack Uses

func MsgPackPack(msg interface{}) ([]byte, error)

func MsgPackUnPack Uses

func MsgPackUnPack(data []byte, msg interface{}) error

func NewDir Uses

func NewDir(path string) error

func NewRedisScript Uses

func NewRedisScript(commit, str string) int

func NewTicker Uses

func NewTicker(ms int) *time.Ticker

func NewTimer Uses

func NewTimer(ms int) *time.Timer

func Now Uses

func Now() time.Time

func PBPack Uses

func PBPack(msg interface{}) ([]byte, error)

func PBUnPack Uses

func PBUnPack(data []byte, msg interface{}) error

func ParseBaseKind Uses

func ParseBaseKind(kind reflect.Kind, data string) (interface{}, error)

func ParseDBData Uses

func ParseDBData(data []byte, v proto.Message) bool

func ParseDBStr Uses

func ParseDBStr(str string, v proto.Message) bool

func ParsePbData Uses

func ParsePbData(data []byte, v proto.Message) bool

func ParsePbStr Uses

func ParsePbStr(str string, v proto.Message) bool

func ParseTime Uses

func ParseTime(str string) (time.Time, error)

func PathAbs Uses

func PathAbs(p string) string

func PathBase Uses

func PathBase(p string) string

func PathClean Uses

func PathClean(p string) string

func PathDir Uses

func PathDir(p string) string

func PathExists Uses

func PathExists(path string) bool

func PathExt Uses

func PathExt(p string) string

func PbData Uses

func PbData(v proto.Message) []byte

func PbStr Uses

func PbStr(v proto.Message) string

func Pow Uses

func Pow(x, y float64) float64

x^y

func Print Uses

func Print(a ...interface{}) (int, error)

func Printf Uses

func Printf(format string, a ...interface{}) (int, error)

func Println Uses

func Println(a ...interface{}) (int, error)

func RandNorm64 Uses

func RandNorm64(sd, mean int32) float64

正态分布:根据标准差和期望生成不同的正态分布值,sd标准差,mean期望

func RandNormInt32 Uses

func RandNormInt32(min, max, sd, mean int32) int32

正态分布,在一定范围内

func RandNumBetween Uses

func RandNumBetween(min, max int) int

min和max之间的随机数

func RandNumber Uses

func RandNumber(number int) int

取0-number区间的随机值

func ReadConfigFromCSV Uses

func ReadConfigFromCSV(path string, nindex int, dataBegin int, f *GenConfigObj) (error, []interface{})

path 文件路径 nindex key值行号,从1开始 dataBegin 数据开始行号,从1开始 f 对象产生器 json:"-" tag字段会被跳过

func ReadConfigFromCSVLie Uses

func ReadConfigFromCSVLie(path string, keyIndex int, valueIndex int, dataBegin int, f *GenConfigObj) (error, interface{})

读取csv字段+值,竖着处理

[in] path       文件路径
[in] keyIndex   需要读取的字段列号
[in] valueIndex 需要读取的字段数据列号
[in] dataBegin  从哪一行开始输出

func ReadConfigFromJson Uses

func ReadConfigFromJson(path string, v interface{}) error

func ReadFile Uses

func ReadFile(path string) ([]byte, error)

func RedisError Uses

func RedisError(err error) bool

func RemoveStopCheck Uses

func RemoveStopCheck(id uint64)

func ReplaceMultStr Uses

func ReplaceMultStr(s string, oldnew ...string) string

func ReplaceStr Uses

func ReplaceStr(s, old, new string) string

func Round Uses

func Round(decimal float64, w int) float32

四舍五入保留n位小数

func Round64 Uses

func Round64(decimal float64, w int) float64

四舍五入保留n位小数

func RoundStr Uses

func RoundStr(format string, decimal float64) string

四舍五入保留n位小数,如保留整数"%.0f",保留3位小数"%.3f"...保留n位小数"%.nf"

func Send Uses

func Send(msg *Message, fun func(msgque IMsgQue) bool)

func SendGroup Uses

func SendGroup(group string, msg *Message)

func SendMail Uses

func SendMail(user, password, host, to, subject, body, mailtype string) error

func SetCSVParseFunc Uses

func SetCSVParseFunc(kind reflect.Kind, fun func(fieldv reflect.Value, data, path string) error)

func SetTimeout Uses

func SetTimeout(inteval int, fn func(...interface{}) int, args ...interface{})

func Sleep Uses

func Sleep(ms int)

func SplitStr Uses

func SplitStr(s string, sep string) []string

func SplitStrN Uses

func SplitStrN(s string, sep string, n int) []string

func Sprintf Uses

func Sprintf(format string, a ...interface{}) string

func Sqrt Uses

func Sqrt(x float64) float64

返回x的二次方根

func StartServer Uses

func StartServer(addr string, typ MsgType, handler IMsgHandler, parser IParserFactory) error

func Stop Uses

func Stop()

func StrContains Uses

func StrContains(s, substr string) bool

func StrFind Uses

func StrFind(s string, f string) int

func StrJoin Uses

func StrJoin(a []string, sep string) string

func StrReplace Uses

func StrReplace(s, old, new string) string

func StrReplaceMult Uses

func StrReplaceMult(s string, oldnew ...string) string

func StrSplit Uses

func StrSplit(s string, sep string) []string

func StrSplitN Uses

func StrSplitN(s string, sep string, n int) []string

func StrToLower Uses

func StrToLower(s string) string

func StrToUpper Uses

func StrToUpper(s string) string

func StrTrim Uses

func StrTrim(s string, cutset []string) string

func StrTrimRight Uses

func StrTrimRight(s, cutset string) string

func StrTrimSpace Uses

func StrTrimSpace(s string) string

func Tag Uses

func Tag(cmd, act uint8, index uint16) int

func Tick Uses

func Tick(ms int) <-chan time.Time

func ToLowerStr Uses

func ToLowerStr(s string) string

func ToUpperStr Uses

func ToUpperStr(s string) string

func TrimRightStr Uses

func TrimRightStr(s, cutset string) string

func TrimStr Uses

func TrimStr(s string, cutset []string) string

func TrimStrSpace Uses

func TrimStrSpace(s string) string

func Try Uses

func Try(fun func(), handler func(interface{}))

func UnixMs Uses

func UnixMs() int64

func UnixNano Uses

func UnixNano() int64

func UnixTime Uses

func UnixTime(sec, nsec int64) time.Time

func WaitForSystemExit Uses

func WaitForSystemExit(atexit ...func())

func WalkDir Uses

func WalkDir(dir string, fun func(dir string, info os.FileInfo))

func WriteFile Uses

func WriteFile(path string, data []byte)

func ZlibCompress Uses

func ZlibCompress(data []byte) []byte

func ZlibUnCompress Uses

func ZlibUnCompress(data []byte) ([]byte, error)

type CmdMatchType Uses

type CmdMatchType int
const (
    CmdMatchTypeK CmdMatchType = iota
    CmdMatchTypeKV
)

type CmdParser Uses

type CmdParser struct {
    *Parser
    // contains filtered or unexported fields
}

func (*CmdParser) GetRemindMsg Uses

func (r *CmdParser) GetRemindMsg(err error, t MsgType) *Message

func (*CmdParser) PackMsg Uses

func (r *CmdParser) PackMsg(v interface{}) []byte

func (*CmdParser) ParseC2S Uses

func (r *CmdParser) ParseC2S(msg *Message) (IMsgParser, error)

type ConnType Uses

type ConnType int
const (
    ConnTypeListen ConnType = iota //监听
    ConnTypeConn                   //连接产生的
    ConnTypeAccept                 //Accept产生的
)

type ConsoleLogger Uses

type ConsoleLogger struct {
    Ln bool
}

func (*ConsoleLogger) Write Uses

func (r *ConsoleLogger) Write(str string)

type DefMsgHandler Uses

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

func (*DefMsgHandler) GetHandlerFunc Uses

func (r *DefMsgHandler) GetHandlerFunc(msgque IMsgQue, msg *Message) HandlerFunc

func (*DefMsgHandler) OnConnectComplete Uses

func (r *DefMsgHandler) OnConnectComplete(msgque IMsgQue, ok bool) bool

func (*DefMsgHandler) OnDelMsgQue Uses

func (r *DefMsgHandler) OnDelMsgQue(msgque IMsgQue)

func (*DefMsgHandler) OnNewMsgQue Uses

func (r *DefMsgHandler) OnNewMsgQue(msgque IMsgQue) bool

func (*DefMsgHandler) OnProcessMsg Uses

func (r *DefMsgHandler) OnProcessMsg(msgque IMsgQue, msg *Message) bool

func (*DefMsgHandler) Register Uses

func (r *DefMsgHandler) Register(cmd, act uint8, fun HandlerFunc)

func (*DefMsgHandler) RegisterMsg Uses

func (r *DefMsgHandler) RegisterMsg(v interface{}, fun HandlerFunc)

type EchoMsgHandler Uses

type EchoMsgHandler struct {
    DefMsgHandler
}

func (*EchoMsgHandler) OnProcessMsg Uses

func (r *EchoMsgHandler) OnProcessMsg(msgque IMsgQue, msg *Message) bool

type ErrJsonStr Uses

type ErrJsonStr struct {
    Error    int    `json:"error"`
    ErrorStr string `json:"errstr"`
}

type Error Uses

type Error struct {
    Id  uint16
    Str string
}

func GetError Uses

func GetError(id uint16) *Error

func NewError Uses

func NewError(str string, id uint16) *Error

func (*Error) Error Uses

func (r *Error) Error() string

type FileLogger Uses

type FileLogger struct {
    Path         string
    Ln           bool
    Timeout      int //0表示不设置, 单位s
    MaxSize      int //0表示不限制,最大大小
    OnFull       OnFileLogFull
    OnTimeout    OnFileLogTimeout
    OnRenameFile OnFileRename
    // contains filtered or unexported fields
}

func (*FileLogger) Write Uses

func (r *FileLogger) Write(str string)

type GenConfigObj Uses

type GenConfigObj struct {
    GenObjFun   func() interface{}
    ParseObjFun map[reflect.Kind]func(fieldv reflect.Value, data, path string) error
}

type HandlerFunc Uses

type HandlerFunc func(msgque IMsgQue, msg *Message) bool

type Heap Uses

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

func NewMaxHeap Uses

func NewMaxHeap() *Heap

func NewMinHeap Uses

func NewMinHeap() *Heap

func (*Heap) GetMax Uses

func (r *Heap) GetMax() (priority int, value int)

func (*Heap) GetMin Uses

func (r *Heap) GetMin() (priority int, value int)

func (*Heap) GetPriority Uses

func (r *Heap) GetPriority(value int) (priority int, find bool)

func (*Heap) Len Uses

func (r *Heap) Len() int

func (*Heap) Pop Uses

func (r *Heap) Pop() int

func (*Heap) Push Uses

func (r *Heap) Push(priority, value int)

func (*Heap) Top Uses

func (r *Heap) Top() int

func (*Heap) Update Uses

func (r *Heap) Update(value, priority int)

type ILogger Uses

type ILogger interface {
    Write(str string)
}

type IMsgHandler Uses

type IMsgHandler interface {
    OnNewMsgQue(msgque IMsgQue) bool                         //新的消息队列
    OnDelMsgQue(msgque IMsgQue)                              //消息队列关闭
    OnProcessMsg(msgque IMsgQue, msg *Message) bool          //默认的消息处理函数
    OnConnectComplete(msgque IMsgQue, ok bool) bool          //连接成功
    GetHandlerFunc(msgque IMsgQue, msg *Message) HandlerFunc //根据消息获得处理函数
}

type IMsgParser Uses

type IMsgParser interface {
    C2S() interface{}
    S2C() interface{}
    C2SData() []byte
    S2CData() []byte
    C2SString() string
    S2CString() string
}

type IMsgQue Uses

type IMsgQue interface {
    Id() uint32
    GetMsgType() MsgType
    GetConnType() ConnType
    GetNetType() NetType

    LocalAddr() string
    RemoteAddr() string
    SetRealRemoteAddr(addr string)

    Stop()
    IsStop() bool
    Available() bool
    IsProxy() 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)
    DelCallback(m *Message)
    SetSendFast()
    SetTimeout(t int)
    SetCmdReadRaw()
    GetTimeout() int
    Reconnect(t int) //重连间隔  最小1s,此函数仅能连接关闭是调用

    GetHandler() IMsgHandler

    SetUser(user interface{})
    GetUser() interface{}

    SetGroupId(group string)
    DelGroupId(group string)
    ClearGroupId(group string)
    IsInGroup(group string) bool

    SetMultiplex(multiplex bool) bool
    // contains filtered or unexported methods
}

func StartConnect Uses

func StartConnect(netype string, addr string, typ MsgType, handler IMsgHandler, parser IParserFactory, user interface{}) IMsgQue

type IParser Uses

type IParser interface {
    GetType() ParserType
    GetErrType() ParseErrType
    ParseC2S(msg *Message) (IMsgParser, error)
    PackMsg(v interface{}) []byte
    GetRemindMsg(err error, t MsgType) *Message
}

type IParserFactory Uses

type IParserFactory interface {
    Get() IParser
}

type JsonParser Uses

type JsonParser struct {
    *Parser
}

func (*JsonParser) GetRemindMsg Uses

func (r *JsonParser) GetRemindMsg(err error, t MsgType) *Message

func (*JsonParser) PackMsg Uses

func (r *JsonParser) PackMsg(v interface{}) []byte

func (*JsonParser) ParseC2S Uses

func (r *JsonParser) ParseC2S(msg *Message) (IMsgParser, error)

type Log Uses

type Log struct {
    // contains filtered or unexported fields
}
var DefLog *Log //日志

func NewLog Uses

func NewLog(bufsize int, logger ...ILogger) *Log

func (*Log) Debug Uses

func (r *Log) Debug(v ...interface{})

func (*Log) Error Uses

func (r *Log) Error(v ...interface{})

func (*Log) Fatal Uses

func (r *Log) Fatal(v ...interface{})

func (*Log) Info Uses

func (r *Log) Info(v ...interface{})

func (*Log) IsStop Uses

func (r *Log) IsStop() bool

func (*Log) Level Uses

func (r *Log) Level() LogLevel

func (*Log) SetLevel Uses

func (r *Log) SetLevel(level LogLevel)

func (*Log) SetLevelByName Uses

func (r *Log) SetLevelByName(name string) bool

func (*Log) SetLogger Uses

func (r *Log) SetLogger(logger ILogger) bool

func (*Log) Stop Uses

func (r *Log) Stop()

func (*Log) Warn Uses

func (r *Log) Warn(v ...interface{})

func (*Log) Write Uses

func (r *Log) Write(v ...interface{})

type LogLevel Uses

type LogLevel int
const (
    LogLevelDebug  LogLevel = iota //调试信息
    LogLevelInfo                   //资讯讯息
    LogLevelWarn                   //警告状况发生
    LogLevelError                  //一般错误,可能导致功能不正常
    LogLevelFatal                  //严重错误,会导致进程退出
    LogLevelAllOff                 //关闭所有日志
)

type Message Uses

type Message struct {
    Head       *MessageHead //消息头,可能为nil
    Data       []byte       //消息数据
    IMsgParser              //解析器
    User       interface{}  //用户自定义数据
}

func NewDataMsg Uses

func NewDataMsg(data []byte) *Message

func NewErrMsg Uses

func NewErrMsg(err error) *Message

func NewForverMsg Uses

func NewForverMsg(cmd, act uint8, index, err uint16, data []byte) *Message

func NewMsg Uses

func NewMsg(cmd, act uint8, index, err uint16, data []byte) *Message

func NewStrMsg Uses

func NewStrMsg(str string) *Message

func NewTagMsg Uses

func NewTagMsg(cmd, act uint8, index uint16) *Message

func (*Message) Act Uses

func (r *Message) Act() uint8

func (*Message) Bytes Uses

func (r *Message) Bytes() []byte

func (*Message) Cmd Uses

func (r *Message) Cmd() uint8

func (*Message) CmdAct Uses

func (r *Message) CmdAct() int

func (*Message) CopyTag Uses

func (r *Message) CopyTag(old *Message) *Message

func (*Message) Error Uses

func (r *Message) Error() uint16

func (*Message) Flags Uses

func (r *Message) Flags() uint16

func (*Message) Index Uses

func (r *Message) Index() uint16

func (*Message) Len Uses

func (r *Message) Len() uint32

func (*Message) Tag Uses

func (r *Message) Tag() int

type MessageHead Uses

type MessageHead struct {
    Len   uint32 //数据长度
    Error uint16 //错误码
    Cmd   uint8  //命令
    Act   uint8  //动作
    Index uint16 //序号
    Flags uint16 //标记
    // contains filtered or unexported fields
}

func MessageHeadFromByte Uses

func MessageHeadFromByte(data []byte) *MessageHead

func NewMessageHead Uses

func NewMessageHead(data []byte) *MessageHead

func (*MessageHead) Bytes Uses

func (r *MessageHead) Bytes() []byte

func (*MessageHead) BytesWithData Uses

func (r *MessageHead) BytesWithData(wdata []byte) []byte

func (*MessageHead) CmdAct Uses

func (r *MessageHead) CmdAct() int

func (*MessageHead) FastBytes Uses

func (r *MessageHead) FastBytes(data []byte) []byte

func (*MessageHead) FromBytes Uses

func (r *MessageHead) FromBytes(data []byte) error

func (*MessageHead) String Uses

func (r *MessageHead) String() string

func (*MessageHead) Tag Uses

func (r *MessageHead) Tag() int

type MsgParser Uses

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

func (*MsgParser) C2S Uses

func (r *MsgParser) C2S() interface{}

func (*MsgParser) C2SData Uses

func (r *MsgParser) C2SData() []byte

func (*MsgParser) C2SString Uses

func (r *MsgParser) C2SString() string

func (*MsgParser) S2C Uses

func (r *MsgParser) S2C() interface{}

func (*MsgParser) S2CData Uses

func (r *MsgParser) S2CData() []byte

func (*MsgParser) S2CString Uses

func (r *MsgParser) S2CString() string

type MsgType Uses

type MsgType int
const (
    MsgTypeMsg MsgType = iota //消息基于确定的消息头
    MsgTypeCmd                //消息没有消息头,以\n分割
)

type MsgpackParser Uses

type MsgpackParser struct {
    *Parser
}

func (*MsgpackParser) GetRemindMsg Uses

func (r *MsgpackParser) GetRemindMsg(err error, t MsgType) *Message

func (*MsgpackParser) PackMsg Uses

func (r *MsgpackParser) PackMsg(v interface{}) []byte

func (*MsgpackParser) ParseC2S Uses

func (r *MsgpackParser) ParseC2S(msg *Message) (IMsgParser, error)

type NetType Uses

type NetType int
const (
    NetTypeTcp NetType = iota //TCP类型
    NetTypeUdp                //UDP类型
    NetTypeWs                 //websocket
)

type OnFileLogFull Uses

type OnFileLogFull func(path string)

type OnFileLogTimeout Uses

type OnFileLogTimeout func(path string) int

type OnFileRename Uses

type OnFileRename func(dirName, fileName, extName string) string

type PBParser Uses

type PBParser struct {
    *Parser
}

func (*PBParser) GetRemindMsg Uses

func (r *PBParser) GetRemindMsg(err error, t MsgType) *Message

func (*PBParser) PackMsg Uses

func (r *PBParser) PackMsg(v interface{}) []byte

func (*PBParser) ParseC2S Uses

func (r *PBParser) ParseC2S(msg *Message) (IMsgParser, error)

type ParseErrType Uses

type ParseErrType int
const (
    ParseErrTypeSendRemind ParseErrType = iota //消息解析失败发送提醒消息
    ParseErrTypeContinue                       //消息解析失败则跳过本条消息
    ParseErrTypeAlways                         //消息解析失败依然处理
    ParseErrTypeClose                          //消息解析失败则关闭连接
)

type ParseFunc Uses

type ParseFunc func() interface{}

type Parser Uses

type Parser struct {
    Type    ParserType
    ErrType ParseErrType
    // contains filtered or unexported fields
}

func (*Parser) Get Uses

func (r *Parser) Get() IParser

func (*Parser) GetErrType Uses

func (r *Parser) GetErrType() ParseErrType

func (*Parser) GetType Uses

func (r *Parser) GetType() ParserType

func (*Parser) Register Uses

func (r *Parser) Register(cmd, act uint8, c2s interface{}, s2c interface{})

func (*Parser) RegisterFunc Uses

func (r *Parser) RegisterFunc(cmd, act uint8, c2sFunc ParseFunc, s2cFunc ParseFunc)

func (*Parser) RegisterMsg Uses

func (r *Parser) RegisterMsg(c2s interface{}, s2c interface{})

func (*Parser) RegisterMsgFunc Uses

func (r *Parser) RegisterMsgFunc(c2sFunc ParseFunc, s2cFunc ParseFunc)

type ParserType Uses

type ParserType int
const (
    ParserTypePB      ParserType = iota //protobuf类型,用于和客户端交互
    ParserTypeCmd                       //cmd类型,类似telnet指令,用于直接和程序交互
    ParserTypeJson                      //json类型,可以用于客户端或者服务器之间交互
    ParserTypeMsgpack                   //msgpack类型,可以用于客户端或者服务器之间交互
    ParserTypeCustom                    //自定义类型
    ParserTypeRaw                       //不做任何解析
)

type Redis Uses

type Redis struct {
    *redis.Client
    // contains filtered or unexported fields
}

func (*Redis) Script Uses

func (r *Redis) Script(cmd int, keys []string, args ...interface{}) (interface{}, error)

func (*Redis) ScriptInt64 Uses

func (r *Redis) ScriptInt64(cmd int, keys []string, args ...interface{}) (int64, error)

func (*Redis) ScriptStr Uses

func (r *Redis) ScriptStr(cmd int, keys []string, args ...interface{}) (string, error)

func (*Redis) ScriptStrArray Uses

func (r *Redis) ScriptStrArray(cmd int, keys []string, args ...interface{}) ([]string, error)

type RedisConfig Uses

type RedisConfig struct {
    Addr     string
    Passwd   string
    PoolSize int
}

type RedisManager Uses

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

func NewRedisManager Uses

func NewRedisManager(conf *RedisConfig) *RedisManager

func (*RedisManager) Add Uses

func (r *RedisManager) Add(id int, conf *RedisConfig)

func (*RedisManager) Exist Uses

func (r *RedisManager) Exist(id int) bool

func (*RedisManager) GetByRid Uses

func (r *RedisManager) GetByRid(rid int) *Redis

func (*RedisManager) GetGlobal Uses

func (r *RedisManager) GetGlobal() *Redis

func (*RedisManager) Sub Uses

func (r *RedisManager) Sub(fun func(channel, data string), channels ...string)

type RedisModel Uses

type RedisModel struct{}

func (*RedisModel) DBData Uses

func (r *RedisModel) DBData(v proto.Message) []byte

func (*RedisModel) DBStr Uses

func (r *RedisModel) DBStr(v proto.Message) string

func (*RedisModel) ParseDBData Uses

func (r *RedisModel) ParseDBData(data []byte, v proto.Message) bool

func (*RedisModel) ParseDBStr Uses

func (r *RedisModel) ParseDBStr(str string, v proto.Message) bool

func (*RedisModel) ParsePbData Uses

func (r *RedisModel) ParsePbData(data []byte, v proto.Message) bool

func (*RedisModel) ParsePbStr Uses

func (r *RedisModel) ParsePbStr(str string, v proto.Message) bool

func (*RedisModel) PbData Uses

func (r *RedisModel) PbData(v proto.Message) []byte

type Statis Uses

type Statis struct {
    GoCount     int
    MsgqueCount int
    StartTime   time.Time
    LastPanic   int
    PanicCount  int32
    PoolGoCount int32
}

func GetStatis Uses

func GetStatis() *Statis

type WaitGroup Uses

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

func (*WaitGroup) Add Uses

func (r *WaitGroup) Add(delta int)

func (*WaitGroup) Done Uses

func (r *WaitGroup) Done()

func (*WaitGroup) TryWait Uses

func (r *WaitGroup) TryWait() bool

func (*WaitGroup) Wait Uses

func (r *WaitGroup) Wait()

Package antnet imports 38 packages (graph). Updated 2019-04-25. Refresh now. Tools for package owners.