Documentation ¶
Index ¶
- Constants
- func DetectContentType(data []byte) string
- func ErrCode(err error, def ...int) int
- func ErrorReply(w http.ResponseWriter, error string, code int)
- func FileServer2(root http.FileSystem) http.Handler
- func GetAppPath() string
- func PanicHandler(forward http.Handler, logwriter func(string)) http.HandlerFunc
- func ParseTime(text string) (t time.Time, err error)
- func RecoverFn(logwriter func(string)) func()
- func ServeFile2(w http.ResponseWriter, r *http.Request, name string)
- type Context
- func (c *Context) Abort()
- func (c *Context) AbortWithStatus(code int)
- func (c *Context) AddError(err error)
- func (c *Context) AddLog(info ...string)
- func (c *Context) ClientIP() string
- func (c *Context) Data(code int, contentType string, data []byte)
- func (c *Context) File(filepath string)
- func (c *Context) Get(key string) (value interface{}, exists bool)
- func (c *Context) GetErrors() []error
- func (c *Context) GetLogs() []string
- func (c *Context) JSON(code int, v interface{})
- func (c *Context) MustGet(key string) interface{}
- func (c *Context) Next()
- func (c *Context) Param(name string) string
- func (c *Context) Query(key string) string
- func (c *Context) QueryByte(key string, def byte) byte
- func (c *Context) QueryFloat64(key string, def float64) float64
- func (c *Context) QueryInt(key string, def int) int
- func (c *Context) QueryInt64(key string, def int64) int64
- func (c *Context) QueryString(key, def string) string
- func (c *Context) QueryUint(key string, def uint) uint
- func (c *Context) ReadBody() []byte
- func (c *Context) ReadReqBodyJson(v interface{}) error
- func (c *Context) Redirect(code int, Location string)
- func (c *Context) Set(key string, value interface{})
- func (c *Context) String(code int, format string, values ...interface{})
- type Engine
- type ErrorWithPos
- type H
- type HandlerFunc
- type IWriter
- type LoggerFunc
- type Router
- func (r *Router) Any(path string, handlers ...HandlerFunc)
- func (r *Router) CONNECT(path string, handlers ...HandlerFunc)
- func (r *Router) DELETE(path string, handlers ...HandlerFunc)
- func (r *Router) GET(path string, handlers ...HandlerFunc)
- func (r *Router) Group(handlers ...HandlerFunc) *Router
- func (r *Router) HEAD(path string, handlers ...HandlerFunc)
- func (r *Router) Handle(method, path string, handlers []HandlerFunc)
- func (r *Router) OPTIONS(path string, handlers ...HandlerFunc)
- func (r *Router) PATCH(path string, handlers ...HandlerFunc)
- func (r *Router) POST(path string, handlers ...HandlerFunc)
- func (r *Router) PUT(path string, handlers ...HandlerFunc)
- func (r *Router) ServeDir(prefix string, dir string)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) TRACE(path string, handlers ...HandlerFunc)
- func (r *Router) Use(middlewares ...HandlerFunc) *Router
- func (r *Router) UseNotFound(fn HandlerFunc)
- type WriterImpl
- func (this *WriterImpl) GetRespBody() io.Reader
- func (this *WriterImpl) GetStatusCode() int
- func (this *WriterImpl) Header() http.Header
- func (this *WriterImpl) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (this *WriterImpl) Init(w http.ResponseWriter)
- func (this *WriterImpl) SetRecordRespBody(bRecordBody bool)
- func (this *WriterImpl) Write(p []byte) (int, error)
- func (this *WriterImpl) WriteHeader(status int)
Constants ¶
const (
AbortIndex = math.MaxInt16 / 2
)
const TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"
TimeFormat is the time format to use when generating times in HTTP headers. It is like time.RFC1123 but hard-codes GMT as the time zone. The time being formatted must be in UTC for Format to generate the correct format.
For parsing this time format, see ParseTime.
const (
Version string = "1.0.3"
)
Variables ¶
This section is empty.
Functions ¶
func DetectContentType ¶
DetectContentType implements the algorithm described at http://mimesniff.spec.whatwg.org/ to determine the Content-Type of the given data. It considers at most the first 512 bytes of data. DetectContentType always returns a valid MIME type: if it cannot determine a more specific one, it returns "application/octet-stream".
func ErrorReply ¶
func ErrorReply(w http.ResponseWriter, error string, code int)
Error replies to the request with the specified error message and HTTP code. It does not otherwise end the request; the caller should ensure no further writes are done to w. The error message should be plain text.
func FileServer2 ¶
func FileServer2(root http.FileSystem) http.Handler
func GetAppPath ¶
func GetAppPath() string
func PanicHandler ¶
func PanicHandler(forward http.Handler, logwriter func(string)) http.HandlerFunc
func ParseTime ¶
ParseTime parses a time header (such as the Date: header), trying each of the three formats allowed by HTTP/1.1: TimeFormat, time.RFC850, and time.ANSIC.
func ServeFile2 ¶
func ServeFile2(w http.ResponseWriter, r *http.Request, name string)
//////////////////////// ServeFile replies to the request with the contents of the named file or directory.
If the provided file or directory name is a relative path, it is interpreted relative to the current directory and may ascend to parent directories. If the provided name is constructed from user input, it should be sanitized before calling ServeFile. As a precaution, ServeFile will reject requests where r.URL.Path contains a ".." path element.
As a special case, ServeFile redirects any request where r.URL.Path ends in "/index.html" to the same path, without the final "index.html". To avoid such redirects either modify the path or use ServeContent.
Types ¶
type Context ¶
type Context struct { Writer IWriter Request *http.Request Keys map[string]interface{} HasError bool // contains filtered or unexported fields }
func (*Context) AbortWithStatus ¶
func (*Context) Get ¶
Get returns the value for the given key, ie: (value, true). If the value does not exists it returns (nil, false)
func (*Context) JSON ¶
code: http response code, eg. 200, 404, ... this function marshal v to json string, and send it to client as http response body.
func (*Context) MustGet ¶
MustGet returns the value for the given key if it exists, otherwise it panics.
func (*Context) QueryString ¶
func (*Context) ReadReqBodyJson ¶
type Engine ¶
type Engine struct { *Router // contains filtered or unexported fields }
func NewServeMux ¶
func NewServeMux() *Engine
type ErrorWithPos ¶
func Error ¶
func Error(err error, code ...int) ErrorWithPos
func ErrorAppend ¶
func ErrorAppend(err error, szExtra ...string) ErrorWithPos
append text description to err, return a new err
func Errorf ¶
func Errorf(code int, format string, a ...interface{}) ErrorWithPos
type HandlerFunc ¶
type HandlerFunc func(*Context)
func Logger ¶
func Logger(bShowReqBody bool, bShowRespBody bool) HandlerFunc
func LoggerWithFunc ¶
func LoggerWithFunc(bShowReqBody bool, bShowRespBody bool, fn LoggerFunc) HandlerFunc
type IWriter ¶
type IWriter interface { http.ResponseWriter http.Hijacker GetStatusCode() int Init(w http.ResponseWriter) SetRecordRespBody(bool) GetRespBody() io.Reader }
func NewWriter ¶
func NewWriter(w http.ResponseWriter) IWriter
type LoggerFunc ¶
func DefaultLoggerFunc ¶
func DefaultLoggerFunc() LoggerFunc
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router http router
func (*Router) Any ¶
func (r *Router) Any(path string, handlers ...HandlerFunc)
Any registers a route that matches all the HTTP methods. GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE
func (*Router) CONNECT ¶
func (r *Router) CONNECT(path string, handlers ...HandlerFunc)
CONNECT handle CONNECT method
func (*Router) DELETE ¶
func (r *Router) DELETE(path string, handlers ...HandlerFunc)
DELETE handle DELETE method
func (*Router) GET ¶
func (r *Router) GET(path string, handlers ...HandlerFunc)
GET handle GET method
func (*Router) HEAD ¶
func (r *Router) HEAD(path string, handlers ...HandlerFunc)
HEAD handle HEAD method
func (*Router) Handle ¶
func (r *Router) Handle(method, path string, handlers []HandlerFunc)
Handle handle with specific method
func (*Router) OPTIONS ¶
func (r *Router) OPTIONS(path string, handlers ...HandlerFunc)
OPTIONS handle OPTIONS method
func (*Router) PATCH ¶
func (r *Router) PATCH(path string, handlers ...HandlerFunc)
PATCH handle PATCH method
func (*Router) POST ¶
func (r *Router) POST(path string, handlers ...HandlerFunc)
POST handle POST method
func (*Router) PUT ¶
func (r *Router) PUT(path string, handlers ...HandlerFunc)
PUT handle PUT method
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
Conforms to the http.Handler interface.
func (*Router) TRACE ¶
func (r *Router) TRACE(path string, handlers ...HandlerFunc)
TRACE handle TRACE method
func (*Router) Use ¶
func (r *Router) Use(middlewares ...HandlerFunc) *Router
Use register middleware these middlewares are combined and added to Router
type WriterImpl ¶
type WriterImpl struct {
// contains filtered or unexported fields
}
func (*WriterImpl) GetRespBody ¶
func (this *WriterImpl) GetRespBody() io.Reader
func (*WriterImpl) GetStatusCode ¶
func (this *WriterImpl) GetStatusCode() int
func (*WriterImpl) Header ¶
func (this *WriterImpl) Header() http.Header
func (*WriterImpl) Hijack ¶
func (this *WriterImpl) Hijack() (net.Conn, *bufio.ReadWriter, error)
func (*WriterImpl) Init ¶
func (this *WriterImpl) Init(w http.ResponseWriter)
func (*WriterImpl) SetRecordRespBody ¶
func (this *WriterImpl) SetRecordRespBody(bRecordBody bool)
func (*WriterImpl) WriteHeader ¶
func (this *WriterImpl) WriteHeader(status int)