Documentation ¶
Index ¶
- Constants
- Variables
- func AnnoToMethod(annoKey string) string
- type Endpoint
- type HTTPRequest
- func (self HTTPRequest) GetBody() []byte
- func (self HTTPRequest) GetCookie(key string) string
- func (self HTTPRequest) GetHeader(key string) string
- func (self HTTPRequest) GetHost() string
- func (self *HTTPRequest) GetMapBody(key string) string
- func (self HTTPRequest) GetMethod() string
- func (self HTTPRequest) GetParam(key string) string
- func (self HTTPRequest) GetPath() string
- func (self HTTPRequest) GetPostForm(key string) string
- func (self HTTPRequest) GetQuery(key string) string
- func (self HTTPRequest) GetUri() string
- type HTTPResponse
- type Param
- type Params
- type RequestGetter
- type ResponseSetter
Constants ¶
const ( // HeaderContentType is the key of Content-Type header HeaderContentType = "Content-Type" // HeaderSetCookie is the key of Set-Cookie header HeaderSetCookie = "Set-Cookie" )
Variables ¶
var (
// DefaultJsonPairSize is the default size of json.Pair slice.
DefaultJsonPairSize = 16
)
Functions ¶
func AnnoToMethod ¶
AnnoToMethod maps annotation to corresponding http method
Types ¶
type HTTPRequest ¶
type HTTPRequest struct { *http.Request Params Params BodyMap interface{} // contains filtered or unexported fields }
Request is a implementation of RequestGetter. It wraps http.Request.
func NewHTTPRequestFromStdReq ¶
func NewHTTPRequestFromStdReq(req *http.Request, params ...Param) (ret *HTTPRequest, err error)
NewHTTPRequestFromStdReq creates a new HTTPRequest from http.Request. It will check the content-type of the request and parse the body if the type one of following:
- application/json
- application/x-www-form-urlencoded
func NewHTTPRequestFromUrl ¶
func NewHTTPRequestFromUrl(method, url string, body io.Reader, params ...Param) (*HTTPRequest, error)
NewHTTPRequestFromUrl creates a new HTTPRequest from url, body and url-path param.
func (HTTPRequest) GetBody ¶
func (self HTTPRequest) GetBody() []byte
Body implements RequestGetter.Body.
func (HTTPRequest) GetCookie ¶
func (self HTTPRequest) GetCookie(key string) string
Cookie implements RequestGetter.Cookie.
func (HTTPRequest) GetHeader ¶
func (self HTTPRequest) GetHeader(key string) string
Header implements RequestGetter.Header.
func (HTTPRequest) GetHost ¶
func (self HTTPRequest) GetHost() string
Host implements RequestGetter.Host.
func (*HTTPRequest) GetMapBody ¶
func (self *HTTPRequest) GetMapBody(key string) string
MapBody implements RequestGetter.MapBody.
func (HTTPRequest) GetMethod ¶
func (self HTTPRequest) GetMethod() string
Method implements RequestGetter.Method.
func (HTTPRequest) GetParam ¶
func (self HTTPRequest) GetParam(key string) string
Param implements RequestGetter.Param.
func (HTTPRequest) GetPath ¶
func (self HTTPRequest) GetPath() string
Path implements RequestGetter.Path.
func (HTTPRequest) GetPostForm ¶
func (self HTTPRequest) GetPostForm(key string) string
PostForm implements RequestGetter.PostForm.
func (HTTPRequest) GetQuery ¶
func (self HTTPRequest) GetQuery(key string) string
Query implements RequestGetter.Query.
func (HTTPRequest) GetUri ¶
func (self HTTPRequest) GetUri() string
Uri implements RequestGetter.Uri.
type HTTPResponse ¶
HTTPResponse is an implementation of ResponseSetter
func NewHTTPResponse ¶
func NewHTTPResponse() *HTTPResponse
NewHTTPResponse creates a new HTTPResponse
func (HTTPResponse) SetCookie ¶
func (self HTTPResponse) SetCookie(key string, val string) error
SetCookie implements ResponseSetter.SetCookie
func (HTTPResponse) SetHeader ¶
func (self HTTPResponse) SetHeader(key string, val string) error
SetHeader implements ResponseSetter.SetHeader
func (HTTPResponse) SetRawBody ¶
func (self HTTPResponse) SetRawBody(body []byte) error
func (HTTPResponse) SetStatusCode ¶
func (self HTTPResponse) SetStatusCode(code int) error
SetStatusCode implements ResponseSetter.SetStatusCode
type Params ¶
type Params struct {
// contains filtered or unexported fields
}
Http url-path params
type RequestGetter ¶
type RequestGetter interface { // GetMethod returns the http method. GetMethod() string // GetHost returns the host. GetHost() string // GetUri returns entire uri. GetUri() string // Header returns the value of the header with the given key. GetHeader(string) string // Cookie returns the value of the cookie with the given key. GetCookie(string) string // Query returns the value of the query with the given key. GetQuery(string) string // Param returns the value of the url-path param with the given key. GetParam(string) string // PostForm returns the value of the post-form body with the given key. GetPostForm(string) string // MapBody returns the value of body with the given key. GetMapBody(string) string // Body returns the raw body in bytes. GetBody() []byte }
RequestGetter is a interface for getting request parameters
type ResponseSetter ¶
type ResponseSetter interface { // SetStatusCode sets the status code of the response SetStatusCode(int) error // SetHeader sets the header of the response SetHeader(string, string) error // SetCookie sets the cookie of the response SetCookie(string, string) error // SetRawBody sets the raw body of the response SetRawBody([]byte) error }
ResponseSetter is a interface for setting response parameters