Documentation ¶
Index ¶
- Constants
- Variables
- func LogDebugPrint(msg string, v interface{})
- func LogGetFileSuffix(now time.Time) string
- func LogGetOsSeparator(pathName string) string
- func LogInit()
- func LogIsDebug() bool
- func LogOpenFile() error
- func LogRun(RunConfigMap map[string]string)
- func LogWriteFile(logMsg LogMsgT)
- func LogfileCleanup(fileLifetime int64)
- func RegisterRpcTypeForValue(value interface{})
- type Config
- func (c *Config) Get(key string) string
- func (c *Config) GetAll() map[string]string
- func (c *Config) GetInt(key string) int
- func (c *Config) GetInt64(key string) int64
- func (c *Config) GetSlice(key string, separator string) []string
- func (c *Config) GetSliceInt(key string, separator string) []int
- func (c *Config) Load(configFile string) error
- type HttpClient
- func (c *HttpClient) Close() error
- func (c *HttpClient) ConnectTo(address string, timeout time.Duration) error
- func (c *HttpClient) Dial(localAddress string, remoteAddress string, timeout time.Duration) error
- func (c *HttpClient) Get(uri string, readTimeout time.Duration, writeTimeout time.Duration) (*HttpResponse, error)
- func (c *HttpClient) Post(uri string, posts map[string]string, readTimeout time.Duration, ...) (*HttpResponse, error)
- func (c *HttpClient) Recv(readTimeout time.Duration) (*HttpResponse, error)
- func (c *HttpClient) Send(request *HttpRequest, writeTimeout time.Duration) error
- func (c *HttpClient) SetDebug(debug bool)
- type HttpConnection
- func (c *HttpConnection) ReadRequest(timeout time.Duration) (*HttpRequest, error)
- func (c *HttpConnection) ReadResponse(timeout time.Duration) (*HttpResponse, error)
- func (c *HttpConnection) WriteRequest(request *HttpRequest, timeout time.Duration) error
- func (c *HttpConnection) WriteResponse(response *HttpResponse, timeout time.Duration) error
- type HttpMessage
- type HttpRequest
- func (r *HttpRequest) Chas(key string) bool
- func (r *HttpRequest) Cint(key string) int
- func (r *HttpRequest) Cookies() map[string]string
- func (r *HttpRequest) Cstr(key string) string
- func (r *HttpRequest) GetRemoteIP() string
- func (r *HttpRequest) Gets() map[string]string
- func (r *HttpRequest) Ghas(key string) bool
- func (r *HttpRequest) Gint(key string) int
- func (r *HttpRequest) Gstr(key string) string
- func (r *HttpRequest) Header(key string) string
- func (r *HttpRequest) IsDelete() bool
- func (r *HttpRequest) IsGet() bool
- func (r *HttpRequest) IsKeepAlive() bool
- func (r *HttpRequest) IsPost() bool
- func (r *HttpRequest) IsPut() bool
- func (r *HttpRequest) Method() string
- func (r *HttpRequest) PathInfo() string
- func (r *HttpRequest) Phas(key string) bool
- func (r *HttpRequest) Pint(key string) int
- func (r *HttpRequest) Posts() map[string]string
- func (r *HttpRequest) Pstr(key string) string
- func (r *HttpRequest) Rint(key string) int
- func (r *HttpRequest) Rstr(key string) string
- func (r *HttpRequest) SetHeader(key string, value string)
- func (r *HttpRequest) SetMethod(method string)
- func (r *HttpRequest) SetPosts(posts map[string]string)
- func (r *HttpRequest) SetUri(uri string)
- func (r *HttpRequest) SetVar(key string, value interface{})
- func (r *HttpRequest) SetVersion(version string)
- func (r *HttpRequest) Stream() []byte
- func (r *HttpRequest) String() string
- func (r *HttpRequest) Uri() string
- func (r *HttpRequest) Var(key string) interface{}
- func (r *HttpRequest) Version() string
- type HttpResponse
- func (r *HttpResponse) BodyStream() []byte
- func (r *HttpResponse) BodyString() string
- func (r *HttpResponse) Code() int
- func (r *HttpResponse) Header(key string) string
- func (r *HttpResponse) IsConnectionClose() bool
- func (r *HttpResponse) Putb(stream []byte)
- func (r *HttpResponse) Puts(content string)
- func (r *HttpResponse) SetBodyStream(bodyStream []byte)
- func (r *HttpResponse) SetBodyString(bodyString string)
- func (r *HttpResponse) SetCode(code int)
- func (r *HttpResponse) SetHeader(key string, value string)
- func (r *HttpResponse) SetStatus(code int, phrase string)
- func (r *HttpResponse) SetVersion(version string)
- func (r *HttpResponse) Status() (int, string)
- func (r *HttpResponse) Stream() []byte
- func (r *HttpResponse) String() string
- func (r *HttpResponse) Version() string
- type LogMsgT
- type LogT
- type Logger
- type RpcRequest
- type RpcResponse
- type TcpConnection
- func (c *TcpConnection) IsHttpProto() bool
- func (c *TcpConnection) Read(p []byte) (n int, err error)
- func (c *TcpConnection) ReadProtoBuffer() error
- func (c *TcpConnection) ReadRpcRequest(timeout time.Duration) (*RpcRequest, error)
- func (c *TcpConnection) ReadStream(stream []byte, count int) error
- func (c *TcpConnection) Rpc(request *RpcRequest, readTimeout time.Duration, writeTimeout time.Duration) (*RpcResponse, error)
- func (c *TcpConnection) WriteRpcResponse(response *RpcResponse, timeout time.Duration) error
- type TcpListener
Constants ¶
const ( LogTypeFatal = 1 LogTypeWarning = 2 LogTypeNotice = 4 LogTypeTrace = 8 LogTypeDebug = 16 )
日志级别类型常量
const ( LogTypeFatalStr = "FATAL" LogTypeWarningStr = "WARNING" LogTypeNoticeStr = "NOTICE" LogTypeTraceStr = "TRACE" LogTypeDebugStr = "DEBUG" )
日志类型对应信息
const ( LogConfNoticeFilePath = "log_notice_file_path" LogConfDebugFilePath = "log_debug_file_path" LogConfTraceFilePath = "log_trace_file_path" LogConfFatalFilePath = "log_fatal_file_path" LogConfWarningFilePath = "log_warning_file_path" LogConfCronTime = "log_cron_time" LogConfChanBuffSize = "log_channel_buff_size" LogConfFlushTimer = "log_flush_timer" LogConfDebugOpen = "log_debug_open" LogConfLevel = "log_level" LogConfFileLifeTime = "log_file_life_time" )
*
- 配置项相关常量&变量
const ( LogConfTypeStr = 1 LogConfTypeNum = 2 )
配置选项值类型(字符串或数字)
Variables ¶
var GConfFileToTypeMap = map[string]int{ LogConfNoticeFilePath: LogTypeNotice, LogConfDebugFilePath: LogTypeDebug, LogConfTraceFilePath: LogTypeTrace, LogConfFatalFilePath: LogTypeFatal, LogConfWarningFilePath: LogTypeWarning, }
GConfFileToTypeMap 日志文件名与日志类型的映射
var GConfItemMap = map[string]int{ LogConfNoticeFilePath: LogConfTypeStr, LogConfDebugFilePath: LogConfTypeStr, LogConfTraceFilePath: LogConfTypeStr, LogConfFatalFilePath: LogConfTypeStr, LogConfWarningFilePath: LogConfTypeStr, LogConfCronTime: LogConfTypeStr, LogConfChanBuffSize: LogConfTypeNum, LogConfFlushTimer: LogConfTypeNum, LogConfDebugOpen: LogConfTypeNum, LogConfLevel: LogConfTypeNum, LogConfFileLifeTime: LogConfTypeNum, }
GConfItemMap 配置项map全局变量 (定义一个选项输入的值是字符串还是数字)
var GFlushLock *sync.Mutex = &sync.Mutex{}
GFlushLock 控制 GFlushLogFlag 的全局锁
var GFlushLogFlag bool = false
GFlushLogFlag 目前是否已经写入刷盘操作channel(保证全局只能写入一次,防止多协程操作阻塞)
var GLogTypeMap = map[int]string{ LogTypeFatal: LogTypeFatalStr, LogTypeWarning: LogTypeWarningStr, LogTypeNotice: LogTypeNoticeStr, LogTypeTrace: LogTypeTraceStr, LogTypeDebug: LogTypeDebugStr, }
GLogTypeMap 日志信息map
var GOnceV sync.Once
GOnceV 全局once
Functions ¶
func LogGetFileSuffix ¶
LogGetFileSuffix . 获取日志文件的切割时间 说明:
目前主要支持三种粒度的设置,基本这些粒度足够我们使用了
1天:day; 1小时:hour; 10分钟:ten
func LogGetOsSeparator ¶
LogGetOsSeparator . 获取当前操作系统的路径切割符 说明: 主要为了解决 os.PathSeparator有些时候无法满足要求的问题
func LogfileCleanup ¶
func LogfileCleanup(fileLifetime int64)
LogfileCleanup . 对notice日志,进行定期清理,执行周期等同于“日志切割周期”
func RegisterRpcTypeForValue ¶
func RegisterRpcTypeForValue(value interface{})
RegisterRpcTypeForValue 注册 rpc 类型
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config .
func (*Config) GetSliceInt ¶
GetSliceInt .
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
HttpClient .
func (*HttpClient) ConnectTo ¶
func (c *HttpClient) ConnectTo(address string, timeout time.Duration) error
ConnectTo .
func (*HttpClient) Get ¶
func (c *HttpClient) Get(uri string, readTimeout time.Duration, writeTimeout time.Duration) (*HttpResponse, error)
Get .
func (*HttpClient) Post ¶
func (c *HttpClient) Post(uri string, posts map[string]string, readTimeout time.Duration, writeTimeout time.Duration) (*HttpResponse, error)
Post .
func (*HttpClient) Recv ¶
func (c *HttpClient) Recv(readTimeout time.Duration) (*HttpResponse, error)
Recv .
func (*HttpClient) Send ¶
func (c *HttpClient) Send(request *HttpRequest, writeTimeout time.Duration) error
Send .
type HttpConnection ¶
type HttpConnection struct { *TcpConnection // 内嵌 *TcpConnection // contains filtered or unexported fields }
HttpConnection .
func NewHttpConnection ¶
func NewHttpConnection(tcpConnection *TcpConnection) *HttpConnection
NewHttpConnection .
func (*HttpConnection) ReadRequest ¶
func (c *HttpConnection) ReadRequest(timeout time.Duration) (*HttpRequest, error)
ReadRequest .
func (*HttpConnection) ReadResponse ¶
func (c *HttpConnection) ReadResponse(timeout time.Duration) (*HttpResponse, error)
ReadResponse .
func (*HttpConnection) WriteRequest ¶
func (c *HttpConnection) WriteRequest(request *HttpRequest, timeout time.Duration) error
WriteRequest .
func (*HttpConnection) WriteResponse ¶
func (c *HttpConnection) WriteResponse(response *HttpResponse, timeout time.Duration) error
WriteResponse .
type HttpMessage ¶
type HttpMessage interface { SetHeader(key string, value string) Header(key string) string Stream() []byte // contains filtered or unexported methods }
HttpMessage .
type HttpRequest ¶
type HttpRequest struct {
// contains filtered or unexported fields
}
HttpRequest .
func (*HttpRequest) SetHeader ¶
func (r *HttpRequest) SetHeader(key string, value string)
SetHeader .
type HttpResponse ¶
type HttpResponse struct {
// contains filtered or unexported fields
}
HttpResponse .
func (*HttpResponse) IsConnectionClose ¶
func (r *HttpResponse) IsConnectionClose() bool
IsConnectionClose .
func (*HttpResponse) SetBodyStream ¶
func (r *HttpResponse) SetBodyStream(bodyStream []byte)
SetBodyStream .
func (*HttpResponse) SetBodyString ¶
func (r *HttpResponse) SetBodyString(bodyString string)
SetBodyString .
func (*HttpResponse) SetHeader ¶
func (r *HttpResponse) SetHeader(key string, value string)
SetHeader .
func (*HttpResponse) SetStatus ¶
func (r *HttpResponse) SetStatus(code int, phrase string)
SetStatus .
type LogT ¶
type LogT struct { // 日志接收channel队列 LogChan chan LogMsgT // 是否马上日志刷盘: true or false,如果为true,则马上日志刷盘 (本chan暂时没有使用) FlushLogChan chan bool // 所有日志文件位置 LogFilePath map[int]string // 日志文件位置 (例:/var/log/koala.log 和 /var/log/koala.log.wf) LogNoticeFilePath string LogErrorFilePath string // 写入日志切割周期(1天:day、1小时:hour、15分钟:Fifteen、10分钟:Ten) LogCronTime string // 日志chan队列的buffer长度,建议不要少于1024,不多于102400,最长:2147483648 LogChanBuffSize int // 按照间隔时间日志刷盘的日志的间隔时间,单位:秒,建议1~5秒,不超过256 LogFlushTimer int // 去重的日志文件名和fd (实际需需要物理写入文件名和句柄) MergeLogFile map[string]string MergeLogFd map[string]*os.File // 上游配置的map数据(必须包含所有所需项) RunConfigMap map[string]string // 是否开启日志库调试模式 LogDebugOpen bool // 日志打印的级别(需要打印那些日志) LogLevel int // 日志文件的存在时间, 单位:天 LogLifeTime int }
LogT Log主chan队列配置
var GLogV *LogT
GLogV .日志全局变量
type Logger ¶
type Logger struct {
LogID string
}
Logger .Log 每次请求结构体数据
type RpcRequest ¶
RpcRequest .
type RpcResponse ¶
type RpcResponse struct { Result bool Reason string Code int Args map[string]interface{} Data interface{} }
RpcResponse .
type TcpConnection ¶
TcpConnection tcp 连接
func TcpConnect ¶
func TcpConnect(localAddress string, remoteAddress string, timeout time.Duration) (*TcpConnection, error)
TcpConnect 连接一个 tcp 地址
func (*TcpConnection) ReadProtoBuffer ¶
func (c *TcpConnection) ReadProtoBuffer() error
ReadProtoBuffer .
func (*TcpConnection) ReadRpcRequest ¶
func (c *TcpConnection) ReadRpcRequest(timeout time.Duration) (*RpcRequest, error)
ReadRpcRequest .
func (*TcpConnection) ReadStream ¶
func (c *TcpConnection) ReadStream(stream []byte, count int) error
ReadStream .
func (*TcpConnection) Rpc ¶
func (c *TcpConnection) Rpc(request *RpcRequest, readTimeout time.Duration, writeTimeout time.Duration) (*RpcResponse, error)
Rpc .
func (*TcpConnection) WriteRpcResponse ¶
func (c *TcpConnection) WriteRpcResponse(response *RpcResponse, timeout time.Duration) error
WriteRpcResponse .