Documentation ¶
Index ¶
- Constants
- Variables
- func CheckServiceEnable(ctx *Context) bool
- func Close()
- func Delete(route string, handler interface{})
- func Get(route string, handler interface{})
- func InitMime() error
- func IsTrustedIP(ctx *Context) bool
- func Match(route string, handler interface{}, method string)
- func NewCookie(name string, value string, age int64) *http.Cookie
- func Post(route string, handler interface{})
- func Process(c http.ResponseWriter, req *http.Request)
- func Put(route string, handler interface{})
- func Run(addr string) (err error)
- func RunFCGI(addr string) (err error)
- func RunSCGI(addr string) (err error)
- func RunTLS(addr string, config *tls.Config) (err error)
- func SetCookieSecret(cookieSecret string) func(*ServerConfig)
- func SetKeepAlive(keepAlive bool) func(*ServerConfig)
- func SetMaxHeaderBytes(maxHeaderBytes int) func(*ServerConfig)
- func SetMaxMemory(maxMemory int64) func(*ServerConfig)
- func SetReadTimeout(readTimeout time.Duration) func(*ServerConfig)
- func SetRecoverPanic(recoverPanic bool) func(*ServerConfig)
- func SetServerConfig(cfg *ServerConfig) func(*Server)
- func SetStaticDir(staticDir string) func(*ServerConfig)
- func SetWriteTimeout(writeTimeout time.Duration) func(*ServerConfig)
- func Slug(s string, sep string) string
- func UrlEncode(data map[string]string) string
- type Context
- func (ctx *Context) Abort(status int, body string)
- func (ctx *Context) AbortBytes(status int, body []byte)
- func (ctx *Context) AcceptsHtml() bool
- func (ctx *Context) AcceptsJson() bool
- func (ctx *Context) AcceptsXml() bool
- func (ctx *Context) ContentType(val string) string
- func (ctx *Context) Cookie(key string) string
- func (ctx *Context) CopyBody() []byte
- func (ctx *Context) Domain() string
- func (ctx *Context) Forbidden()
- func (ctx *Context) GetBasicAuth() (string, string, error)
- func (ctx *Context) GetSecureCookie(name string) (string, bool)
- func (ctx *Context) Header(key string) string
- func (ctx *Context) Host() string
- func (ctx *Context) IP() string
- func (ctx *Context) Is(method string) bool
- func (ctx *Context) IsAjax() bool
- func (ctx *Context) IsDelete() bool
- func (ctx *Context) IsGet() bool
- func (ctx *Context) IsHead() bool
- func (ctx *Context) IsOptions() bool
- func (ctx *Context) IsPatch() bool
- func (ctx *Context) IsPost() bool
- func (ctx *Context) IsPut() bool
- func (ctx *Context) IsSecure() bool
- func (ctx *Context) IsUpload() bool
- func (ctx *Context) IsWebsocket() bool
- func (ctx *Context) Method() string
- func (ctx *Context) NotFound(message string)
- func (ctx *Context) NotModified()
- func (ctx *Context) Param(key string, def ...string) string
- func (ctx *Context) ParamBol(key string, def ...bool) bool
- func (ctx *Context) ParamF32(key string, def ...float32) float32
- func (ctx *Context) ParamF64(key string, def ...float64) float64
- func (ctx *Context) ParamI(key string, def ...int) int
- func (ctx *Context) ParamI16(key string, def ...int16) int16
- func (ctx *Context) ParamI32(key string, def ...int32) int32
- func (ctx *Context) ParamI64(key string, def ...int64) int64
- func (ctx *Context) ParamI8(key string, def ...int8) int8
- func (ctx *Context) ParamStr(key string, def ...string) string
- func (ctx *Context) ParamU(key string, def ...uint) uint
- func (ctx *Context) ParamU16(key string, def ...uint16) uint16
- func (ctx *Context) ParamU32(key string, def ...uint32) uint32
- func (ctx *Context) ParamU64(key string, def ...uint64) uint64
- func (ctx *Context) ParamU8(key string, def ...uint8) uint8
- func (ctx *Context) ParseFormOrMutliForm(maxMemory int64) error
- func (ctx *Context) Port() int
- func (ctx *Context) Protocol() string
- func (ctx *Context) Proxy() []string
- func (ctx *Context) Redirect(status int, url_ string)
- func (ctx *Context) Refer() string
- func (ctx *Context) Referer() string
- func (ctx *Context) Scheme() string
- func (ctx *Context) SetCacheControl(expires time.Duration)
- func (ctx *Context) SetCookie(cookie *http.Cookie)
- func (ctx *Context) SetExpires(expires time.Duration)
- func (ctx *Context) SetHeader(hdr string, val string, unique bool)
- func (ctx *Context) SetLastModified(modTime time.Time)
- func (ctx *Context) SetSecureCookie(name string, val string, age int64)
- func (ctx *Context) Site() string
- func (ctx *Context) SubDomains() string
- func (ctx *Context) TraceErrorf(format string, a ...interface{})
- func (ctx *Context) TraceFinish()
- func (ctx *Context) TracePrintf(format string, a ...interface{})
- func (ctx *Context) Unauthorized()
- func (ctx *Context) Uri() string
- func (ctx *Context) Url() string
- func (ctx *Context) UserAgent() string
- func (ctx *Context) WriteBytes(content []byte)
- func (ctx *Context) WriteString(content string)
- type ContextHandler
- type Server
- func (s *Server) Close()
- func (s *Server) Closed() bool
- func (s *Server) Delete(route string, handler interface{})
- func (s *Server) Get(route string, handler interface{})
- func (s *Server) Handler(route string, method string, httpHandler http.Handler)
- func (s *Server) Match(route string, handler interface{}, method string)
- func (s *Server) Matches(route string, handler interface{}, methods ...string)
- func (s *Server) Post(route string, handler interface{})
- func (s *Server) Process(c http.ResponseWriter, req *http.Request)
- func (s *Server) Put(route string, handler interface{})
- func (s *Server) Run(addr string)
- func (s *Server) RunFCGI(addr string)
- func (s *Server) RunMux(basePattern, addr string)
- func (s *Server) RunSCGI(addr string)
- func (s *Server) RunTLS(addr string, config *tls.Config)
- func (s *Server) RunTLSMux(addr string, config *tls.Config)
- func (s *Server) ServeHTTP(c http.ResponseWriter, req *http.Request)
- type ServerConfig
- type Service
Constants ¶
const MAXN_RETRY_TIMES = 60
Variables ¶
var ( // run mode, "debug" or "release" RunMode string CopyRequestBody bool HttpHead = "Backend WebServer" IndentJson bool = true )
var Config = NewServerConfig()
Functions ¶
func Delete ¶
func Delete(route string, handler interface{})
Delete adds a handler for the 'DELETE' http method in the main server.
func Get ¶
func Get(route string, handler interface{})
Get adds a handler for the 'GET' http method in the main server.
func NewCookie ¶
NewCookie is a helper method that returns a new http.Cookie object. Duration is specified in seconds. If the duration is zero, the cookie is permanent. This can be used in conjunction with ctx.SetCookie.
func Post ¶
func Post(route string, handler interface{})
Post adds a handler for the 'POST' http method in the main server.
func Process ¶
func Process(c http.ResponseWriter, req *http.Request)
Process invokes the main server's routing system.
func Put ¶
func Put(route string, handler interface{})
Put adds a handler for the 'PUT' http method in the main server.
func SetCookieSecret ¶
func SetCookieSecret(cookieSecret string) func(*ServerConfig)
func SetKeepAlive ¶
func SetKeepAlive(keepAlive bool) func(*ServerConfig)
func SetMaxHeaderBytes ¶
func SetMaxHeaderBytes(maxHeaderBytes int) func(*ServerConfig)
func SetMaxMemory ¶
func SetMaxMemory(maxMemory int64) func(*ServerConfig)
func SetReadTimeout ¶
func SetReadTimeout(readTimeout time.Duration) func(*ServerConfig)
func SetRecoverPanic ¶
func SetRecoverPanic(recoverPanic bool) func(*ServerConfig)
func SetServerConfig ¶
func SetServerConfig(cfg *ServerConfig) func(*Server)
func SetStaticDir ¶
func SetStaticDir(staticDir string) func(*ServerConfig)
func SetWriteTimeout ¶
func SetWriteTimeout(writeTimeout time.Duration) func(*ServerConfig)
Types ¶
type Context ¶
type Context struct { Request *http.Request RequestBody []byte Params map[string]string Server *Server http.ResponseWriter // contains filtered or unexported fields }
func (*Context) Abort ¶
Abort is a helper method that sends an HTTP header and an optional body. It is useful for returning 4xx or 5xx errors. Once it has been called, any return value from the handler will not be written to the response.
func (*Context) AbortBytes ¶
Abort is a helper method that sends an HTTP header and an optional body. It is useful for returning 4xx or 5xx errors. Once it has been called, any return value from the handler will not be written to the response.
func (*Context) AcceptsHtml ¶
Checks if request accepts html response
func (*Context) AcceptsJson ¶
Checks if request accepts json response
func (*Context) AcceptsXml ¶
Checks if request accepts xml response
func (*Context) ContentType ¶
ContentType sets the Content-Type header for an HTTP response. For example, ctx.ContentType("json") sets the content-type to "application/json" If the supplied value contains a slash (/) it is set as the Content-Type verbatim. The return value is the content type as it was set, or an empty string if none was found.
func (*Context) Cookie ¶
Cookie returns request cookie item string by a given key. if non-existed, return empty string.
func (*Context) GetBasicAuth ¶
GetBasicAuth is a helper method of *Context that returns the decoded user and password from the *Context's authorization header
func (*Context) Header ¶
Header returns request header item string by a given string. if non-existed, return empty string.
func (*Context) IP ¶
IP returns request client ip. if in proxy, return first proxy id. if error, return 127.0.0.1.
func (*Context) IsUpload ¶
IsUpload returns boolean of whether file uploads in this request or not..
func (*Context) IsWebsocket ¶
IsWebsocket returns boolean of this request is in webSocket.
func (*Context) NotModified ¶
func (ctx *Context) NotModified()
Notmodified writes a 304 HTTP response
func (*Context) ParseFormOrMutliForm ¶
parseForm or parseMultiForm based on Content-type
func (*Context) SetCacheControl ¶
func (*Context) SetExpires ¶
func (*Context) SetHeader ¶
SetHeader sets a response header. If `unique` is true, the current value of that header will be overwritten . If false, it will be appended.
func (*Context) SetLastModified ¶
func (*Context) SetSecureCookie ¶
func (*Context) SubDomains ¶
SubDomains returns sub domain string. if aa.bb.domain.com, returns aa.bb .
func (*Context) TraceErrorf ¶
func (*Context) TraceFinish ¶
func (ctx *Context) TraceFinish()
func (*Context) TracePrintf ¶
func (*Context) Unauthorized ¶
func (ctx *Context) Unauthorized()
Unauthorized writes a 401 HTTP response
func (*Context) WriteBytes ¶
WriteString writes string data into the response object.
func (*Context) WriteString ¶
WriteString writes string data into the response object.
type ContextHandler ¶
type Server ¶
type Server struct { Config *ServerConfig Env map[string]interface{} // contains filtered or unexported fields }
Server represents a web.go server.
func (*Server) Handler ¶
Adds a custom handler. Only for webserver mode. Will have no effect when running as FCGI or SCGI.
func (*Server) Process ¶
func (s *Server) Process(c http.ResponseWriter, req *http.Request)
Process invokes the routing system for server s
type ServerConfig ¶
type ServerConfig struct { StaticDir string CookieSecret string RecoverPanic bool KeepAlive bool ReadTimeout time.Duration WriteTimeout time.Duration MaxHeaderBytes int MaxMemory int64 }
ServerConfig is configuration for server objects.
func NewServerConfig ¶
func NewServerConfig(options ...func(*ServerConfig)) *ServerConfig
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func InvokeService ¶
根据结构体的方法名注册为http服务方法 handler's kind must be ptr