Documentation ¶
Index ¶
- Variables
- func BuildVersion() string
- func CheckErrorExit(err ...interface{})
- func ClientGet(url string, timeOut time.Duration) ([]byte, error)
- func ClientPost(url string, data interface{}, contentType string, timeOut time.Duration) ([]byte, error)
- func CloseConn(wsConn *websocket.Conn, conn *ImplConnection)
- func DELETE(pattern string, handler func(*HTTPContext))
- func FileAppend(fileName string, fileBytes []byte) bool
- func FileDel(fileName string) bool
- func FileExist(fileName string) bool
- func FileMkdir(fileName string) bool
- func FileReadAll(fileName string) []byte
- func GET(pattern string, handler func(*HTTPContext))
- func GlobalSignalRelease()
- func GlobalSignalWait()
- func ListenAndServe(addr string)
- func LogDebug(a ...interface{})
- func LogDebugF(format string, a ...interface{})
- func LogError(a ...interface{})
- func LogErrorF(format string, a ...interface{})
- func LogInfo(a ...interface{})
- func LogInfoF(format string, a ...interface{})
- func LogInit(level string, maxSize int64)
- func LogWarning(a ...interface{})
- func LogWarningF(format string, a ...interface{})
- func POST(pattern string, handler func(*HTTPContext))
- func PUBLIC(pattern, path string)
- func PUT(pattern string, handler func(*HTTPContext))
- func Regist(regist_url string)
- func SQLDelete(tableName, where string) (int64, error)
- func SQLInit(driverName, dataSourceName string, maxOpenConns, maxIdleConns int) error
- func SQLInsert(tableName string, data []byte) (int64, error)
- func SQLQueryByMap(columnName, feilds, tableName, where, order string, offset, count int) (interface{}, error)
- func SQLUpdate(tableName, where string, data []byte) (int64, error)
- func STATUS(status int, handler func(*HTTPContext))
- func SqlQueryRows(feilds, tableName, where, order string, offset, count int) (*sql.Rows, error)
- func StartHTTP(port int)
- func StartWebSocket(pattern string, port int, ...)
- func StringifyMultiLine() string
- func StringifySingleLine() string
- func TimeGetNowStr() (time_str string)
- func TimeIntToDuration(sec int) time.Duration
- func TimeSleepSecond(sec int)
- func WebSocketSendToAll(b []byte)
- func WebSocketSendToGroup(b []byte, groupName string)
- type HTTPContext
- func (ctx *HTTPContext) GetInt(key string, def ...int) int
- func (ctx *HTTPContext) GetInt64(key string, def ...int64) int64
- func (ctx *HTTPContext) GetPathParam(key string) string
- func (ctx *HTTPContext) GetPostBody() []byte
- func (ctx *HTTPContext) GetR() *http.Request
- func (ctx *HTTPContext) GetRequest() *http.Request
- func (ctx *HTTPContext) GetResponseWriter() http.ResponseWriter
- func (ctx *HTTPContext) GetString(key string, def ...string) string
- func (ctx *HTTPContext) GetW() http.ResponseWriter
- func (ctx *HTTPContext) Redirect(url string, status int)
- func (ctx *HTTPContext) WriteByte(content []byte)
- func (ctx *HTTPContext) WriteExecute(data interface{}, filenames ...string) error
- func (ctx *HTTPContext) WriteHeader(key, value string)
- func (ctx *HTTPContext) WriteHeaderContentType(value string)
- func (ctx *HTTPContext) WriteHeaderStatus(status int)
- func (ctx *HTTPContext) WriteJSON(v interface{}) error
- func (ctx *HTTPContext) WriteParse(data interface{}, tmplContents ...string) error
- func (ctx *HTTPContext) WriteString(content string)
- type ImplConnection
- func (conn *ImplConnection) Close()
- func (conn *ImplConnection) GetGroup() string
- func (conn *ImplConnection) OutGroup()
- func (conn *ImplConnection) ReadMessage() (data []byte, err error)
- func (conn *ImplConnection) RemoteAddr() net.Addr
- func (conn *ImplConnection) SetGroup(groupName string)
- func (conn *ImplConnection) WriteMessage(data []byte) (err error)
- type RecvJsonStruct
- type TaskModel
Constants ¶
This section is empty.
Variables ¶
var ( // 初始化为 unknown,如果编译时没有传入这些值,则为 unknown GitCommitLog = "unknown" GitStatus = "unknown" BuildTime = "unknown" BuildGoVersion = "unknown" )
var (
ImplConnMap map[string]*ImplConnection
)
var ProcHandle func([]byte, *ImplConnection) ([]byte, error)
ProcHandle 开发者注册的回调函数,初始化为nil,在RunWebSocket函数中会赋值 []byte 接收到的内容 *ImplConnection 发送接口指针,可用此指针回复相应客户端
Functions ¶
func BuildVersion ¶
func BuildVersion() string
func CheckErrorExit ¶
func CheckErrorExit(err ...interface{})
func ClientPost ¶
func ClientPost(url string, data interface{}, contentType string, timeOut time.Duration) ([]byte, error)
ClientPost 发送POST请求 url: 请求地址 data: POST请求提交的数据 contentType:请求体格式,如:application/json timeOut: 请求超时时间,单位秒
func CloseConn ¶
func CloseConn(wsConn *websocket.Conn, conn *ImplConnection)
func DELETE ¶
func DELETE(pattern string, handler func(*HTTPContext))
DELETE 注册DELETE请求函数,注册固定URL、解析URL函数 pattern string:触发路径 handler httpProcFunc: 触发函数
func FileAppend ¶
func FileReadAll ¶
func GET ¶
func GET(pattern string, handler func(*HTTPContext))
GET 注册GET请求函数,注册固定URL、解析URL函数 pattern string:触发路径 handler httpProcFunc: 触发函数
func LogDebugF ¶
func LogDebugF(format string, a ...interface{})
LogDebugF 日志输出和官方fmt.Print、fmt.Printf使用一致
func LogErrorF ¶
func LogErrorF(format string, a ...interface{})
LogErrorF 日志输出和官方fmt.Print、fmt.Printf使用一致
func LogInfoF ¶
func LogInfoF(format string, a ...interface{})
LogInfoF 日志输出和官方fmt.Print、fmt.Printf使用一致
func LogInit ¶
LogInit 初始化日志输出功能 level 日志输出级别
配置文件指定日志级别 ALL,DEBUG,INFO,WARN,ERROR,FATAL,OFF 级别由低到高 其中 ALL表示所有调用打印日志的方法都会打出,而OFF则表示都不会打出。 一般习惯是测试阶段为debug,生成环境为info以上
maxSize 日志文件最大体积,单位MB
func LogWarningF ¶
func LogWarningF(format string, a ...interface{})
LogWarningF 日志输出和官方fmt.Print、fmt.Printf使用一致
func POST ¶
func POST(pattern string, handler func(*HTTPContext))
POST 注册POST请求函数,注册固定URL、解析URL函数 pattern string:触发路径 handler httpProcFunc: 触发函数
func PUBLIC ¶
func PUBLIC(pattern, path string)
PUBLIC 注册PUBLIC请求函数,可以共享文件查看下载 pattern string:触发路径 handler httpProcFunc: 触发函数
func PUT ¶
func PUT(pattern string, handler func(*HTTPContext))
PUT 注册PUT请求函数,注册固定URL、解析URL函数 pattern string:触发路径 handler httpProcFunc: 触发函数
func SQLInit ¶
SQLInit 初始化数据库操作句柄,这里要提供: driverName string: 数据库类型,例如mysql、sqlite等,参考github.com/go-sql-driver/mysql官方介绍 dataSourceName string: 数据库地址,参考github.com/go-sql-driver/mysql官方介绍 MaxOpenConns int: 最大缓存连接数,这个数值包含了MaxIdleConns MaxIdleConns int:预备的最大空闲连接数
func SQLQueryByMap ¶
func SQLQueryByMap(columnName, feilds, tableName, where, order string, offset, count int) (interface{}, error)
SQLQueryByMap 将查询到的数据,按照指定字段的值做为索引构建map并返回 columnName string: 作为索引的字段名称 feilds string: 查询需要获取哪些字段的值,就是select后面跟着的部分,一般用"*" tableName string: 查询的表名 where string: 过滤条件,就是where后面跟着的部分 order string: 排序条件,就是order by后面跟着的部分。默认是ASC排序,除非"-"开头则DESC排序 offset string: limit后面逗号相隔的两个数值,前者就是offset,后者就是count count string: limit后面逗号相隔的两个数值,前者就是offset,后者就是count
func SQLUpdate ¶
SQLUpdate 更新一条数据 tableName string: 操作的表名 where string: 过滤条件,就是where后面跟着的部分 data []byte: 需要更新的内容,用string转换后是json格式
func STATUS ¶
func STATUS(status int, handler func(*HTTPContext))
STATUS 注册指定HTTP状态触发的函数 status int:触发状态 handler httpProcFunc: 触发函数
func SqlQueryRows ¶
func StartHTTP ¶
func StartHTTP(port int)
StartHTTP 启动HTTP服务 gorouter.Run() default run on HttpPort gorouter.Run("localhost") gorouter.Run(":8089") gorouter.Run("127.0.0.1:8089")
func StartWebSocket ¶
func StartWebSocket(pattern string, port int, handler func([]byte, *ImplConnection) ([]byte, error))
StartWebSocket 启动websocket服务 pattern 服务路径 port 端口号 handler 注册回调函数
func TimeGetNowStr ¶
func TimeGetNowStr() (time_str string)
func TimeIntToDuration ¶
func TimeSleepSecond ¶
func TimeSleepSecond(sec int)
func WebSocketSendToAll ¶
func WebSocketSendToAll(b []byte)
WebSocketSendToAll 向所有连接的websocket客户端发送消息 b byte[]格式的消息内容
func WebSocketSendToGroup ¶
WebSocketSendToGroup 向指定分组的websocket客户端发送消息,分组通过WebSocketSetGroup函数接口设置 b byte[]格式的消息内容 group 分组名称
Types ¶
type HTTPContext ¶
type HTTPContext struct {
// contains filtered or unexported fields
}
HTTPContext 提供给客户使用的扩展指针,包含了原始的http.ResponseWriter和http.Request,同时还提供了封装好的一系列方便函数
func (*HTTPContext) GetInt ¶
func (ctx *HTTPContext) GetInt(key string, def ...int) int
GetInt 获取GET请求?后面的int参数值 key string: 参数名称 def ...int: 参数可选,当获取参数值无效的时候,便返回这里提供的值
func (*HTTPContext) GetInt64 ¶
func (ctx *HTTPContext) GetInt64(key string, def ...int64) int64
GetInt64 获取GET请求?后面的int64参数值 key string: 参数名称 def ...int64: 参数可选,当获取参数值无效的时候,便返回这里提供的值
func (*HTTPContext) GetPathParam ¶
func (ctx *HTTPContext) GetPathParam(key string) string
GetPathParam 获取GET请求路径中的String格式参数值,例如/restful/:table_name/:id key string: 参数名称
func (*HTTPContext) GetPostBody ¶
func (ctx *HTTPContext) GetPostBody() []byte
GetPostBody 获取POST请求的内容
func (*HTTPContext) GetRequest ¶
func (ctx *HTTPContext) GetRequest() *http.Request
GetRequest 获取原始的http.Request
func (*HTTPContext) GetResponseWriter ¶
func (ctx *HTTPContext) GetResponseWriter() http.ResponseWriter
GetResponseWriter 获取原始的http.ResponseWriter
func (*HTTPContext) GetString ¶
func (ctx *HTTPContext) GetString(key string, def ...string) string
GetString 获取GET请求?后面的String参数值, key string: 参数名称 def ...string: 参数可选,当获取参数值无效的时候,便返回这里提供的值
func (*HTTPContext) GetW ¶
func (ctx *HTTPContext) GetW() http.ResponseWriter
GetW 获取原始的http.ResponseWriter
func (*HTTPContext) Redirect ¶
func (ctx *HTTPContext) Redirect(url string, status int)
Redirect 网页跳转 url string: 跳转的url status int: 需要写入头部的状态,例如http.StatusOK
func (*HTTPContext) WriteByte ¶
func (ctx *HTTPContext) WriteByte(content []byte)
WriteByte 将[]byte格式的数据输出给HTTP客户端 content []byte: 需要输出HTTP客户端的[]byte格式数据
func (*HTTPContext) WriteExecute ¶
func (ctx *HTTPContext) WriteExecute(data interface{}, filenames ...string) error
WriteExecute 将官方原始的ParseFiles和Execute接口做了合并 data interface{}: 渲染模板需要的数据 filenames ...string: 模板文件路径
func (*HTTPContext) WriteHeader ¶
func (ctx *HTTPContext) WriteHeader(key, value string)
WriteHeader 将String格式的value设置到Header头部key字段
func (*HTTPContext) WriteHeaderContentType ¶
func (ctx *HTTPContext) WriteHeaderContentType(value string)
WriteHeaderContentType 返回信息类型Content-Type
func (*HTTPContext) WriteHeaderStatus ¶
func (ctx *HTTPContext) WriteHeaderStatus(status int)
WriteHeaderStatus 指定Status到头部输出给HTTP客户端 status int: HTTP状态, 参考net\http\status.go
func (*HTTPContext) WriteJSON ¶
func (ctx *HTTPContext) WriteJSON(v interface{}) error
WriteJSON 将Struct结构体的数据转换成Json输出给HTTP客户端 v interface{}: 需要输出HTTP客户端的Struct结构体数据
func (*HTTPContext) WriteParse ¶
func (ctx *HTTPContext) WriteParse(data interface{}, tmplContents ...string) error
func (*HTTPContext) WriteString ¶
func (ctx *HTTPContext) WriteString(content string)
WriteString 将String格式的数据输出给HTTP客户端 content string: 需要输出HTTP客户端的String格式数据
type ImplConnection ¶
type ImplConnection struct {
// contains filtered or unexported fields
}
func InitImplConnection ¶
func InitImplConnection(wsConn *websocket.Conn) (conn *ImplConnection, err error)
InitImplConnection 初始化长连接
func (*ImplConnection) GetGroup ¶
func (conn *ImplConnection) GetGroup() string
GetGroup 获取websocket客户端的分组信息
func (*ImplConnection) OutGroup ¶
func (conn *ImplConnection) OutGroup()
OutGroup 设置指定websocket客户端的分组 conn websocket客户端连接句柄 group 分组名称
func (*ImplConnection) ReadMessage ¶
func (conn *ImplConnection) ReadMessage() (data []byte, err error)
ReadMessage 读取数据
func (*ImplConnection) RemoteAddr ¶
func (conn *ImplConnection) RemoteAddr() net.Addr
RemoteAddr 获取客户端IP
func (*ImplConnection) SetGroup ¶
func (conn *ImplConnection) SetGroup(groupName string)
SetGroup 设置指定websocket客户端的分组 conn websocket客户端连接句柄 group 分组名称
func (*ImplConnection) WriteMessage ¶
func (conn *ImplConnection) WriteMessage(data []byte) (err error)
WriteMessage 发送数据
type RecvJsonStruct ¶
type TaskModel ¶
type TaskModel struct {
// contains filtered or unexported fields
}
func (*TaskModel) SendRelease ¶
func (c *TaskModel) SendRelease()