Documentation ¶
Index ¶
- Constants
- func CORSDefault(header http.Header) http.Header
- type ApiJsonResult
- type Client
- type ClientResponse
- func Connect(url string, data ...interface{}) (*ClientResponse, error)
- func Delete(url string, data ...interface{}) (*ClientResponse, error)
- func DoRequest(method, url string, data ...interface{}) (*ClientResponse, error)
- func Get(url string, data ...interface{}) (*ClientResponse, error)
- func Head(url string, data ...interface{}) (*ClientResponse, error)
- func Options(url string, data ...interface{}) (*ClientResponse, error)
- func Patch(url string, data ...interface{}) (*ClientResponse, error)
- func Post(url string, data ...interface{}) (*ClientResponse, error)
- func Put(url string, data ...interface{}) (*ClientResponse, error)
- type Group
- type HandlerFunc
- type MiddlewareFunc
- type Request
- func (r *Request) GetBody() []byte
- func (r *Request) GetBodyString() string
- func (r *Request) GetBool(key string, def ...interface{}) bool
- func (r *Request) GetClientIp() string
- func (r *Request) GetFloat32(key string, def ...interface{}) float32
- func (r *Request) GetFloat64(key string, def ...interface{}) float64
- func (r *Request) GetForm(key string, def ...interface{}) interface{}
- func (r *Request) GetHost() string
- func (r *Request) GetInt(key string, def ...interface{}) int
- func (r *Request) GetInt32(key string, def ...interface{}) int32
- func (r *Request) GetInt64(key string, def ...interface{}) int64
- func (r *Request) GetParam(key string, def ...interface{}) interface{}
- func (r *Request) GetQuery(key string, def ...interface{}) interface{}
- func (r *Request) GetQueryParams() interface{}
- func (r *Request) GetReferer() string
- func (r *Request) GetRemoteIp() string
- func (r *Request) GetRequest(key string, def ...interface{}) interface{}
- func (r *Request) GetRequestBool(key string, def ...interface{}) bool
- func (r *Request) GetRequestFloat32(key string, def ...interface{}) float32
- func (r *Request) GetRequestFloat64(key string, def ...interface{}) float64
- func (r *Request) GetRequestInt(key string, def ...interface{}) int
- func (r *Request) GetRequestInt32(key string, def ...interface{}) int32
- func (r *Request) GetRequestInt64(key string, def ...interface{}) int64
- func (r *Request) GetRequestString(key string, def ...interface{}) string
- func (r *Request) GetRequestUint(key string, def ...interface{}) uint
- func (r *Request) GetRequestUint32(key string, def ...interface{}) uint32
- func (r *Request) GetRequestUint64(key string, def ...interface{}) uint64
- func (r *Request) GetRequestUint8(key string, def ...interface{}) uint8
- func (r *Request) GetRequestVar(key string, def ...interface{}) *gvar.Var
- func (r *Request) GetString(key string, def ...interface{}) string
- func (r *Request) GetUint(key string, def ...interface{}) uint
- func (r *Request) GetUint32(key string, def ...interface{}) uint32
- func (r *Request) GetUint64(key string, def ...interface{}) uint64
- func (r *Request) GetUint8(key string, def ...interface{}) uint8
- func (r *Request) GetUrl() string
- type Response
- type ResponseWriter
- type Router
- type Server
Constants ¶
const ( ServerStatusStopped = 0 ServerStatusRunning = 1 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ApiJsonResult ¶
type ClientResponse ¶
func Connect ¶
func Connect(url string, data ...interface{}) (*ClientResponse, error)
Connect is a convenience method for sending CONNECT request. NOTE that remembers CLOSING the response object when it'll never be used.
func Delete ¶
func Delete(url string, data ...interface{}) (*ClientResponse, error)
Delete is a convenience method for sending DELETE request. NOTE that remembers CLOSING the response object when it'll never be used.
func DoRequest ¶
func DoRequest(method, url string, data ...interface{}) (*ClientResponse, error)
DoRequest is a convenience method for sending custom http method request. NOTE that remembers CLOSING the response object when it'll never be used.
func Get ¶
func Get(url string, data ...interface{}) (*ClientResponse, error)
Get is a convenience method for sending GET request. NOTE that remembers CLOSING the response object when it'll never be used.
func Head ¶
func Head(url string, data ...interface{}) (*ClientResponse, error)
Head is a convenience method for sending HEAD request. NOTE that remembers CLOSING the response object when it'll never be used. Deprecated, please use g.Client().Head or NewClient().Head instead.
func Options ¶
func Options(url string, data ...interface{}) (*ClientResponse, error)
Options is a convenience method for sending OPTIONS request. NOTE that remembers CLOSING the response object when it'll never be used.
func Patch ¶
func Patch(url string, data ...interface{}) (*ClientResponse, error)
Patch is a convenience method for sending PATCH request. NOTE that remembers CLOSING the response object when it'll never be used. Deprecated, please use g.Client().Patch or NewClient().Patch instead.
func Post ¶
func Post(url string, data ...interface{}) (*ClientResponse, error)
Post is a convenience method for sending POST request. NOTE that remembers CLOSING the response object when it'll never be used.
func Put ¶
func Put(url string, data ...interface{}) (*ClientResponse, error)
Put is a convenience method for sending PUT request. NOTE that remembers CLOSING the response object when it'll never be used.
type Group ¶
路由组
func (*Group) AddRoute ¶
func (g *Group) AddRoute(name string, handlerFunc HandlerFunc, middleware ...MiddlewareFunc)
AddRoute 添加路由
func (*Group) Use ¶
func (g *Group) Use(middleware ...MiddlewareFunc) *Group
type HandlerFunc ¶
type HandlerFunc func(req *Request)
type MiddlewareFunc ¶
type MiddlewareFunc func(HandlerFunc) HandlerFunc
type Request ¶
type Request struct { *http.Request Response *Response // Corresponding Response of this request. // contains filtered or unexported fields }
Request is the context object for a request.
func NewRequest ¶
func NewRequest(r *http.Request, w http.ResponseWriter) *Request
NewRequest creates and returns a new request object.
func (*Request) GetBody ¶
GetBody retrieves and returns request body content as bytes. It can be called multiple times retrieving the same body content.
func (*Request) GetBodyString ¶
GetBodyString retrieves and returns request body content as string. It can be called multiple times retrieving the same body content.
func (*Request) GetBool ¶
GetBool is an alias and convenient function for GetRequestBool. See GetRequestBool.
func (*Request) GetClientIp ¶
GetClientIp returns the client ip of this request without port. Note that this ip address might be modified by client header.
func (*Request) GetFloat32 ¶
GetFloat32 is an alias and convenient function for GetRequestFloat32. See GetRequestFloat32.
func (*Request) GetFloat64 ¶
GetFloat64 is an alias and convenient function for GetRequestFloat64. See GetRequestFloat64.
func (*Request) GetForm ¶
GetForm retrieves and returns parameter <key> from form. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetHost ¶
GetHost returns current request host name, which might be a domain or an IP without port.
func (*Request) GetInt ¶
GetInt is an alias and convenient function for GetRequestInt. See GetRequestInt.
func (*Request) GetInt32 ¶
GetInt32 is an alias and convenient function for GetRequestInt32. See GetRequestInt32.
func (*Request) GetInt64 ¶
GetInt64 is an alias and convenient function for GetRequestInt64. See GetRequestInt64.
func (*Request) GetParam ¶
GetParam returns custom parameter with given name <key>. It returns <def> if <key> does not exist. It returns nil if <def> is not passed.
func (*Request) GetQuery ¶
GetQuery retrieves and returns parameter with given name <key> from query string and request body. It returns <def> if <key> does not exist in the query and <def> is given, or else it returns nil.
Note that if there're multiple parameters with the same name, the parameters are retrieved and overwrote in order of priority: query > body.
func (*Request) GetQueryParams ¶
func (r *Request) GetQueryParams() interface{}
GetQueryParams return all parameters by GET Http Method
func (*Request) GetReferer ¶
GetReferer returns referer of this request.
func (*Request) GetRemoteIp ¶
GetRemoteIp returns the ip from RemoteAddr.
func (*Request) GetRequest ¶
GetRequest retrieves and returns the parameter named <key> passed from client and custom params as interface{}, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
GetRequest is one of the most commonly used functions for retrieving parameters.
Note that if there're multiple parameters with the same name, the parameters are retrieved and overwrote in order of priority: router < query < body < form < custom.
func (*Request) GetRequestBool ¶
GetRequestBool retrieves and returns the parameter named <key> passed from client and custom params as bool, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestFloat32 ¶
GetRequestFloat32 retrieves and returns the parameter named <key> passed from client and custom params as float32, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestFloat64 ¶
GetRequestFloat64 retrieves and returns the parameter named <key> passed from client and custom params as float64, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestInt ¶
GetRequestInt retrieves and returns the parameter named <key> passed from client and custom params as int, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestInt32 ¶
GetRequestInt32 retrieves and returns the parameter named <key> passed from client and custom params as int32, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestInt64 ¶
GetRequestInt64 retrieves and returns the parameter named <key> passed from client and custom params as int64, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestString ¶
GetRequestString retrieves and returns the parameter named <key> passed from client and custom params as string, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestUint ¶
GetRequestUint retrieves and returns the parameter named <key> passed from client and custom params as uint, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestUint32 ¶
GetRequestUint32 retrieves and returns the parameter named <key> passed from client and custom params as uint32, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestUint64 ¶
GetRequestUint64 retrieves and returns the parameter named <key> passed from client and custom params as uint64, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestUint8 ¶
GetRequestUint retrieves and returns the parameter named <key> passed from client and custom params as uint, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestVar ¶
GetRequestVar retrieves and returns the parameter named <key> passed from client and custom params as gvar.Var, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetString ¶
GetString is an alias and convenient function for GetRequestString. See GetRequestString.
func (*Request) GetUint ¶
GetUint is an alias and convenient function for GetRequestUint. See GetRequestUint.
func (*Request) GetUint32 ¶
GetUint32 is an alias and convenient function for GetRequestUint32. See GetRequestUint32.
func (*Request) GetUint64 ¶
GetUint64 is an alias and convenient function for GetRequestUint64. See GetRequestUint64.
type Response ¶
type Response struct { *ResponseWriter // Underlying ResponseWriter. Writer *ResponseWriter // Alias of ResponseWriter. Request *Request // According request. }
Response is the ghttp response manager. Note that it implements the ghttp.ResponseWriter interface with buffering feature.
func NewResponse ¶
func NewResponse(w http.ResponseWriter) *Response
NewResponse creates and returns a new Response object.
func (*Response) ApiSuccess ¶
func (r *Response) ApiSuccess(data interface{})
type ResponseWriter ¶
type ResponseWriter struct { Status int // HTTP status. // contains filtered or unexported fields }
ResponseWriter is the custom writer for ghttp response.
func (*ResponseWriter) Flush ¶
func (w *ResponseWriter) Flush()
OutputBuffer outputs the buffer to client and clears the buffer.
func (*ResponseWriter) Header ¶
func (w *ResponseWriter) Header() http.Header
Header implements the interface function of ghttp.ResponseWriter.Header.
func (*ResponseWriter) RawWriter ¶
func (w *ResponseWriter) RawWriter() http.ResponseWriter
RawWriter returns the underlying ResponseWriter.
func (*ResponseWriter) Write ¶
func (w *ResponseWriter) Write(data []byte) (int, error)
Write implements the interface function of ghttp.ResponseWriter.Write.
func (*ResponseWriter) WriteHeader ¶
func (w *ResponseWriter) WriteHeader(status int)
WriteHeader implements the interface of ghttp.ResponseWriter.WriteHeader.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) AddRoute ¶
func (s *Server) AddRoute(path string, handler HandlerFunc, middleware ...MiddlewareFunc)
添加路由
Source Files ¶
- ghttp_client.go
- ghttp_request.go
- ghttp_request_param.go
- ghttp_request_param_form.go
- ghttp_request_param_param.go
- ghttp_request_param_query.go
- ghttp_request_param_request.go
- ghttp_response.go
- ghttp_response_api.go
- ghttp_response_cors.go
- ghttp_response_write.go
- ghttp_response_writer.go
- ghttp_router.go
- ghttp_server.go