Documentation
¶
Index ¶
- func DELETE(pattern string, handler func(*HTTPContext))
- func GET(pattern string, handler func(*HTTPContext))
- func Log() *go_logger.Logger
- func POST(pattern string, handler func(*HTTPContext))
- func PUT(pattern string, handler func(*HTTPContext))
- func Run(addr 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))
- 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(status int)
- func (ctx *HTTPContext) WriteJSON(v interface{}) error
- func (ctx *HTTPContext) WriteString(content string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DELETE ¶
func DELETE(pattern string, handler func(*HTTPContext))
DELETE 注册DELETE请求函数,注册固定URL、解析URL函数 pattern string:触发路径 handler httpProcFunc: 触发函数
func GET ¶
func GET(pattern string, handler func(*HTTPContext))
GET 注册GET请求函数,注册固定URL、解析URL函数 pattern string:触发路径 handler httpProcFunc: 触发函数
func Log ¶
func Log() *go_logger.Logger
Log GoGo使用的第三方go_logger库,输出到日志文件的同时还会在控制台输出,并根据日志级别显示不同颜色 这里返回go_logger的指针,使用方法参考github.com/phachon/go-logger
func POST ¶
func POST(pattern string, handler func(*HTTPContext))
POST 注册POST请求函数,注册固定URL、解析URL函数 pattern string:触发路径 handler httpProcFunc: 触发函数
func PUT ¶
func PUT(pattern string, handler func(*HTTPContext))
PUT 注册PUT请求函数,注册固定URL、解析URL函数 pattern string:触发路径 handler httpProcFunc: 触发函数
func Run ¶
func Run(addr string)
Run gorouter application. gorouter.Run() default run on HttpPort gorouter.Run("localhost") gorouter.Run(":8089") gorouter.Run("127.0.0.1:8089")
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: 触发函数
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(status int)
WriteHeader 指定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) WriteString ¶
func (ctx *HTTPContext) WriteString(content string)
WriteString 将String格式的数据输出给HTTP客户端 content string: 需要输出HTTP客户端的String格式数据