package config const ( // 系统错误号定义,最低号为110,最高127 MIN_SYSTEM_ERROR_CODE = 110 // 系统信息最小值 NEXT_SUBSCRIBE = 111 NEXT_MIDDLE = 112 CONVERT_FAILED = 113 FORBIDDEN = 120 SYSTEM_ERROR = 123 GET_TIMEOUT = 124 CONNECT_NO_MATCH = 125 CONNECT_END = 126 NO_MATCH = 127 MAX_SYSTEM_ERROR_CODE = 127 //系统信息最大值 ) // 转换 id 到对应的消息 func IdMsg(id int) string { switch id { case NEXT_SUBSCRIBE: return "NEXT SUBSCRIBE" case NEXT_MIDDLE: return "NEXT MIDDLE" case CONVERT_FAILED: return "CONVERT FAILED" case FORBIDDEN: return "FORBIDDEN" case SYSTEM_ERROR: return "SYSTEM ERROR" case GET_TIMEOUT: return "GET TIMEOUT" case CONNECT_NO_MATCH: return "CONNECT NO MATCH" case CONNECT_END: return "CONNECT END" case NO_MATCH: return "NO MATCH" } return "UNKNOWN" } // 定义成功与失败的值 const STATE_OK = 1 const STATE_FAILED = 0 const ( // ID 号最高值,高于这个值的ID号为系统内部使用 ID_MAX = 65500 // 验证ID ID_AUTH = 65502 ) // 全局配置 type Config struct { ConnectTimeout int // 没有收到数据包的连接超时时间(ms) PingInterval int // 发送ping包的时间间隔,前提是没有收到数据包(ms) WriteWait int // 写入网络数据等待最长时间(ms) ReadWait int // 获取命令数据超时时间 (ms) LongReadWait int // 长时间等待读取数据的超时时间(ms) CleanDeadConnectWait int // 清理异常的连接(ms) PrintPing bool // 打印连接ping包 PrintMsg bool // 打印数据包 ProxyTimeout int // 客户端检测是否使用代理连接,如果是则进行直连尝试(ms) ConnectCheck int // 客户端重连检测周期(ms) } // 获取实例好的配置 func NewConfig() *Config { // 配置基础的数据 return &Config{ ConnectTimeout: 30 * 1000, PingInterval: 61 * 1000, WriteWait: 60 * 1000, ReadWait: 30 * 1000, LongReadWait: 150 * 1000, CleanDeadConnectWait: 3600 * 1000, PrintPing: false, PrintMsg: true, ProxyTimeout: 3600 * 1000, ConnectCheck: 600 * 1000, } }