Documentation ¶
Index ¶
- Constants
- Variables
- func AccessLogFilter(reply Reply, chain FilterChain)
- type Config
- type ConvertError
- type Filter
- type FilterChain
- type HTTPError
- type PathFragment
- func (pf PathFragment) Get(key string) (RequestParam, error)
- func (pf PathFragment) GetAsFloat32(key string) (float32, error)
- func (pf PathFragment) GetAsFloat64(key string) (float64, error)
- func (pf PathFragment) GetAsInt(key string) (int, error)
- func (pf PathFragment) GetAsInt32(key string) (int32, error)
- func (pf PathFragment) GetAsInt64(key string) (int64, error)
- func (pf PathFragment) GetAsString(key string) (string, error)
- func (pf PathFragment) GetAsTime(key string, layout string) (time.Time, error)
- type Render
- type RenderJSON
- type RenderText
- type RenderXML
- type Reply
- type RequestErrorHandler
- type RequestHandler
- type RequestMethod
- type RequestParam
- func (rp RequestParam) AsFloat32() (float32, error)
- func (rp RequestParam) AsFloat64() (float64, error)
- func (rp RequestParam) AsInt() (int, error)
- func (rp RequestParam) AsInt32() (int32, error)
- func (rp RequestParam) AsInt64() (int64, error)
- func (rp RequestParam) AsString() string
- func (rp RequestParam) AsTime(layout string) (time.Time, error)
- type Server
- type URIPatternMatcher
Constants ¶
const ( //GET GET Method GET = RequestMethod(http.MethodGet) //HEAD HEAD Method HEAD = RequestMethod(http.MethodHead) //POST POST Method POST = RequestMethod(http.MethodPost) //PUT PUT Method PUT = RequestMethod(http.MethodPut) //PATCH PATCH Method PATCH = RequestMethod(http.MethodPatch) //DELETE DELETE Method DELETE = RequestMethod(http.MethodDelete) //CONNECT CONNECT Method CONNECT = RequestMethod(http.MethodConnect) //OPTIONS OPTIONS Method OPTIONS = RequestMethod(http.MethodOptions) //TRACE TRACE Method TRACE = RequestMethod(http.MethodTrace) )
Variables ¶
var ( //DefaultCharset 默认的字符集 DefaultCharset = "utf-8" //DefaultRenderJSON 默认的 Json 渲染器 DefaultRenderJSON = RenderJSON{Charset: DefaultCharset} //DefaultRenderXML 默认的 Xml 渲染器 DefaultRenderXML = RenderXML{Charset: DefaultCharset} //DefaultRenderText 默认的 Text 渲染器 DefaultRenderText = RenderText{Charset: DefaultCharset} )
var EmptyParam = RequestParam("")
EmptyParam 空参数
Functions ¶
func AccessLogFilter ¶
func AccessLogFilter(reply Reply, chain FilterChain)
AccessLogFilter 访问日志的 Filter, 在 consol 上输出每个被访问的 url 及响应时间
Types ¶
type Config ¶
type Config struct { ServerAddr string `json:"server_addr" yaml:"server_addr"` //ServerAddr server地址 ReadTimeout time.Duration `json:"read_timeout" yaml:"read_timeout"` // 读的最大Timeout时间 WriteTimeout time.Duration `json:"write_timeout" yaml:"write_timeout"` // 写的最大Timeout时间 MaxHeaderBytes int `json:"max_header_bytes" yaml:"max_header_bytes"` // 请求头的最大长度 TLSConfig *tls.Config // 配置TLS TLSNextProto map[string]func(*http.Server, *tls.Conn, http.Handler) ConnState func(net.Conn, http.ConnState) HTTPErrorLogout io.Writer DefaultRender Render KeepAliveDuration time.Duration `json:"keep_alive_duration" yaml:"keep_alive_duration"` IdleTimeout time.Duration `json:"idle_timeout" yaml:"idle_timeout"` RootContext context.Context }
Config http server Config
func (*Config) GetRootContext ¶
type ConvertError ¶
type ConvertError struct {
// contains filtered or unexported fields
}
ConvertError 请求参数转换错误
func (ConvertError) Error ¶
func (ce ConvertError) Error() string
type HTTPError ¶
type HTTPError struct { Code int `json:"httpcode"` Message interface{} `json:"message"` }
HTTPError 对 http 处理的过程中异常的封装
type PathFragment ¶
type PathFragment map[string]RequestParam
PathFragment 动态 Path 里面的变量片段
func (PathFragment) Get ¶
func (pf PathFragment) Get(key string) (RequestParam, error)
Get get RequestParam form key
func (PathFragment) GetAsFloat32 ¶
func (pf PathFragment) GetAsFloat32(key string) (float32, error)
GetAsFloat32 get a float32 from key
func (PathFragment) GetAsFloat64 ¶
func (pf PathFragment) GetAsFloat64(key string) (float64, error)
GetAsFloat64 get a float64 from key
func (PathFragment) GetAsInt ¶
func (pf PathFragment) GetAsInt(key string) (int, error)
GetAsInt get a int from key
func (PathFragment) GetAsInt32 ¶
func (pf PathFragment) GetAsInt32(key string) (int32, error)
GetAsInt32 get a int32 form key
func (PathFragment) GetAsInt64 ¶
func (pf PathFragment) GetAsInt64(key string) (int64, error)
GetAsInt64 get a int64 from from key
func (PathFragment) GetAsString ¶
func (pf PathFragment) GetAsString(key string) (string, error)
GetAsString get a string form key
type Render ¶
type Render interface { ContentType() string Render(data interface{}) (io.ReadCloser, error) }
Render 渲染器接口
type RenderJSON ¶
type RenderJSON struct {
Charset string
}
RenderJSON json格式的渲染器
func (RenderJSON) ContentType ¶
func (render RenderJSON) ContentType() string
ContentType implement Render func
func (RenderJSON) Render ¶
func (render RenderJSON) Render(data interface{}) (io.ReadCloser, error)
Write implement Render func
type RenderText ¶
type RenderText struct {
Charset string
}
RenderText text格式的渲染器
func (RenderText) ContentType ¶
func (render RenderText) ContentType() string
ContentType implement Render func
func (RenderText) Render ¶
func (render RenderText) Render(data interface{}) (io.ReadCloser, error)
Write implement Render func
type RenderXML ¶
type RenderXML struct {
Charset string
}
RenderXML xml格式的渲染器
func (RenderXML) ContentType ¶
ContentType implement Render func
type Reply ¶
type Reply interface { GetStatusCode() int SetStatusCode(statusCode int) Reply SetCookie(cookie http.Cookie) Reply SetHeader(key, value string) Reply AddHeader(key, value string) Reply DelHeader(key string) Reply GetHeader(key string) string Header() http.Header Redirect(code int, url string) Reply AddPathFragment(k, v string) With(data interface{}) Reply As(render Render) Reply GetRequest() *http.Request GetResponseWriter() http.ResponseWriter GetPathFragment() PathFragment AdapterHTTPHandler(adapter bool) //包装一层ResponseWriter,如 Gzip WarpResponseWriter(http.ResponseWriter) GetContext() context.Context SetContext(key string, value interface{}) }
Reply a wapper for http requese and response
type RequestErrorHandler ¶
RequestErrorHandler 请求异常的处理方法定义
type RequestParam ¶
type RequestParam string
RequestParam 统一Request 请求参数类型
func (RequestParam) AsFloat32 ¶
func (rp RequestParam) AsFloat32() (float32, error)
AsFloat32 to float32
func (RequestParam) AsFloat64 ¶
func (rp RequestParam) AsFloat64() (float64, error)
AsFloat64 to float64
type Server ¶
type Server interface { Start() <-chan error Stop() GetServerAddress() string RegisterHandlerFunc(path string, method RequestMethod, handlerFunc http.HandlerFunc) error RegisterHandler(path string, method RequestMethod, handler http.Handler) error Register(path string, method RequestMethod, requestHandler RequestHandler) error AddFirstFilter(uriPattern string, actionFilter Filter) AddLastFilter(uriPattern string, actionFilter Filter) AddFilterWithRegex(uriPattern string, actionFilter Filter) AddRequestErrorHandler(code int, handler RequestErrorHandler) error }
Server the http server interface
type URIPatternMatcher ¶
type URIPatternMatcher interface {
// contains filtered or unexported methods
}
URIPatternMatcher a URI matcher interface