Documentation ¶
Index ¶
- Constants
- Variables
- func Debugf(fmt string, v ...interface{})
- func Debugln(v ...interface{})
- func Errorf(fmt string, v ...interface{})
- func Errorln(v ...interface{})
- func Fatalf(fmt string, v ...interface{})
- func Fatalln(v ...interface{})
- func Flush()
- func Infof(fmt string, v ...interface{})
- func Infoln(v ...interface{})
- func RegisterLogger(logger Logger)
- func Warnf(fmt string, v ...interface{})
- func Warnln(v ...interface{})
- type APIFunc
- type APIResult
- type APIRouter
- type HTTPContext
- func (c *HTTPContext) GetFormValueInt64(key string, def int64) int64
- func (c *HTTPContext) GetFormValueString(key string) string
- func (c *HTTPContext) GetFormValueStringTrimBlank(key string) string
- func (c *HTTPContext) GetPathVarInt64(key string, def int64) int64
- func (c *HTTPContext) GetPathVarString(key string) string
- func (c *HTTPContext) GetPathVersion() string
- func (c *HTTPContext) GetRequest() *http.Request
- func (c *HTTPContext) GetResponseWriter() http.ResponseWriter
- func (c *HTTPContext) GetUserData(key string) interface{}
- func (c *HTTPContext) ReadBody() ([]byte, error)
- func (c *HTTPContext) SetRequest(r *http.Request)
- func (c *HTTPContext) SetUserData(key string, value interface{})
- func (c *HTTPContext) UnmarshalJSONFromBody(i interface{}) error
- type HTTPServer
- type Logger
- type SwappableHandler
Constants ¶
View Source
const ( LogLevelDebug = iota LogLevelInfo LogLevelWarn LogLevelError LogLevelFatal )
Variables ¶
View Source
var ( ErrInvalidServerRouter = errors.New("Invalid server router") ErrInvalidListenAddress = errors.New("Invalid listen address") )
constant errors
Functions ¶
func RegisterLogger ¶
func RegisterLogger(logger Logger)
Types ¶
type APIFunc ¶
type APIFunc func(*HTTPContext) *APIResult
type APIResult ¶
type APIResult struct { Message string `json:"message"` ResultCode int `json:"code"` Data interface{} `json:"data"` // For internal use StatusCode int `json:"-"` RawBytes []byte `json:"-"` // If raw is not nil, directly send raw bytes rather than sending json bytes of the result // Original error Err error `json:"-"` }
APIError holds the error code and error message for responding to request peer
func NewAPIResult ¶
type APIRouter ¶
APIRouter defines an interface to determine which handler is called by path and method
type HTTPContext ¶
type HTTPContext struct {
// contains filtered or unexported fields
}
func (*HTTPContext) GetFormValueInt64 ¶
func (c *HTTPContext) GetFormValueInt64(key string, def int64) int64
func (*HTTPContext) GetFormValueString ¶
func (c *HTTPContext) GetFormValueString(key string) string
func (*HTTPContext) GetFormValueStringTrimBlank ¶
func (c *HTTPContext) GetFormValueStringTrimBlank(key string) string
func (*HTTPContext) GetPathVarInt64 ¶
func (c *HTTPContext) GetPathVarInt64(key string, def int64) int64
func (*HTTPContext) GetPathVarString ¶
func (c *HTTPContext) GetPathVarString(key string) string
func (*HTTPContext) GetPathVersion ¶
func (c *HTTPContext) GetPathVersion() string
func (*HTTPContext) GetRequest ¶
func (c *HTTPContext) GetRequest() *http.Request
func (*HTTPContext) GetResponseWriter ¶
func (c *HTTPContext) GetResponseWriter() http.ResponseWriter
func (*HTTPContext) GetUserData ¶
func (c *HTTPContext) GetUserData(key string) interface{}
func (*HTTPContext) ReadBody ¶
func (c *HTTPContext) ReadBody() ([]byte, error)
func (*HTTPContext) SetRequest ¶
func (c *HTTPContext) SetRequest(r *http.Request)
func (*HTTPContext) SetUserData ¶
func (c *HTTPContext) SetUserData(key string, value interface{})
func (*HTTPContext) UnmarshalJSONFromBody ¶
func (c *HTTPContext) UnmarshalJSONFromBody(i interface{}) error
type HTTPServer ¶
type HTTPServer struct {
// contains filtered or unexported fields
}
func NewHTTPServer ¶
func NewHTTPServer(address string) *HTTPServer
func (*HTTPServer) AppendRouters ¶
func (s *HTTPServer) AppendRouters(rts ...APIRouter)
AppendRouters create mux and update handler of server
func (*HTTPServer) EnablePprof ¶
func (s *HTTPServer) EnablePprof()
func (*HTTPServer) GetListener ¶
func (s *HTTPServer) GetListener() net.Listener
GetListener get the listener of the server
func (*HTTPServer) SetNotFoundHandler ¶
func (s *HTTPServer) SetNotFoundHandler(h APIFunc)
SetNotFoundHandler -
type SwappableHandler ¶
type SwappableHandler struct {
// contains filtered or unexported fields
}
SwappableHandler is a http.Handler thats allows you to swap mux during working
func (*SwappableHandler) ServeHTTP ¶
func (h *SwappableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implement the http.Handler interface
func (*SwappableHandler) Swap ¶
func (h *SwappableHandler) Swap(r *mux.Router)
Swap swaps the router of the handler
Click to show internal directories.
Click to hide internal directories.