import "github.com/cloudwego/dynamicgo/http"- Constants
- Variables
- func AnnoToMethod(annoKey string) string
- type Endpoint
- type HTTPRequest
- func NewHTTPRequest() *HTTPRequest
- func NewHTTPRequestFromStdReq(req *http.Request, params ...Param) (ret *HTTPRequest, err error)
- func NewHTTPRequestFromUrl(method, url string, body io.Reader, params ...Param) (*HTTPRequest, error)
- func (self HTTPRequest) Body() []byte
- func (self HTTPRequest) Cookie(key string) string
- func (self HTTPRequest) Header(key string) string
- func (self HTTPRequest) Host() string
- func (self *HTTPRequest) MapBody(key string) string
- func (self HTTPRequest) Method() string
- func (self HTTPRequest) Param(key string) string
- func (self HTTPRequest) Path() string
- func (self HTTPRequest) PostForm(key string) string
- func (self HTTPRequest) Query(key string) string
- func (self HTTPRequest) Uri() string
- type HTTPResponse
- type Param
- type Params
- type RequestGetter
- type ResponseSetter
const (
// HeaderContentType is the key of Content-Type header
HeaderContentType = "Content-Type"
// HeaderSetCookie is the key of Set-Cookie header
HeaderSetCookie = "Set-Cookie"
)var (
// DefaultJsonPairSize is the default size of json.Pair slice.
DefaultJsonPairSize = 16
)func AnnoToMethod(annoKey string) stringAnnoToMethod maps annotation to corresponding http method
Endpoint a http endpoint.
type Endpoint struct {
Method, Path string
}Request is a implementation of RequestGetter. It wraps http.Request.
type HTTPRequest struct {
*http.Request
Params Params
BodyMap interface{}
// contains filtered or unexported fields
}func NewHTTPRequest() *HTTPRequestNewHTTPRequest creates a new HTTPRequest.
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(method, url string, body io.Reader, params ...Param) (*HTTPRequest, error)NewHTTPRequestFromUrl creates a new HTTPRequest from url, body and url-path param.
func (self HTTPRequest) Body() []byteBody implements RequestGetter.Body.
func (self HTTPRequest) Cookie(key string) stringCookie implements RequestGetter.Cookie.
func (self HTTPRequest) Header(key string) stringHeader implements RequestGetter.Header.
func (self HTTPRequest) Host() stringHost implements RequestGetter.Host.
func (self *HTTPRequest) MapBody(key string) stringMapBody implements RequestGetter.MapBody.
func (self HTTPRequest) Method() stringMethod implements RequestGetter.Method.
func (self HTTPRequest) Param(key string) stringParam implements RequestGetter.Param.
func (self HTTPRequest) Path() stringPath implements RequestGetter.Path.
func (self HTTPRequest) PostForm(key string) stringPostForm implements RequestGetter.PostForm.
func (self HTTPRequest) Query(key string) stringQuery implements RequestGetter.Query.
func (self HTTPRequest) Uri() stringUri implements RequestGetter.Uri.
HTTPResponse is an implementation of ResponseSetter
type HTTPResponse struct {
*http.Response
}func NewHTTPResponse() *HTTPResponseNewHTTPResponse creates a new HTTPResponse
func (self HTTPResponse) SetCookie(key string, val string) errorSetCookie implements ResponseSetter.SetCookie
func (self HTTPResponse) SetHeader(key string, val string) errorSetHeader implements ResponseSetter.SetHeader
func (self HTTPResponse) SetRawBody(body []byte) errorfunc (self HTTPResponse) SetStatusCode(code int) errorSetStatusCode implements ResponseSetter.SetStatusCode
e.g. /user/:id + /user/123 => Param{Key: "id", Value: "123"}
type Param struct {
Key string
Value string
}Http url-path params
type Params struct {
// contains filtered or unexported fields
}func (ps *Params) ByName(name string) stringByName search Param by given name
func (ps *Params) Recycle()Recycle the Params
func (ps *Params) Set(name string, val string) boolSet set Param by given name and value, return true if Param exists
RequestGetter is a interface for getting request parameters
type RequestGetter interface {
// Method returns the http method.
Method() string
// Host returns the host.
Host() string
// Uri returns entire uri.
Uri() string
// Header returns the value of the header with the given key.
Header(string) string
// Cookie returns the value of the cookie with the given key.
Cookie(string) string
// Query returns the value of the query with the given key.
Query(string) string
// Param returns the value of the url-path param with the given key.
Param(string) string
// PostForm returns the value of the post-form body with the given key.
PostForm(string) string
// MapBody returns the value of body with the given key.
MapBody(string) string
// Body returns the raw body in bytes.
Body() []byte
}ResponseSetter is a interface for setting response parameters
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
}Generated by gomarkdoc