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) string
AnnoToMethod 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() *HTTPRequest
NewHTTPRequest 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() []byte
Body implements RequestGetter.Body.
func (self HTTPRequest) Cookie(key string) string
Cookie implements RequestGetter.Cookie.
func (self HTTPRequest) Header(key string) string
Header implements RequestGetter.Header.
func (self HTTPRequest) Host() string
Host implements RequestGetter.Host.
func (self *HTTPRequest) MapBody(key string) string
MapBody implements RequestGetter.MapBody.
func (self HTTPRequest) Method() string
Method implements RequestGetter.Method.
func (self HTTPRequest) Param(key string) string
Param implements RequestGetter.Param.
func (self HTTPRequest) Path() string
Path implements RequestGetter.Path.
func (self HTTPRequest) PostForm(key string) string
PostForm implements RequestGetter.PostForm.
func (self HTTPRequest) Query(key string) string
Query implements RequestGetter.Query.
func (self HTTPRequest) Uri() string
Uri implements RequestGetter.Uri.
HTTPResponse is an implementation of ResponseSetter
type HTTPResponse struct {
*http.Response
}
func NewHTTPResponse() *HTTPResponse
NewHTTPResponse creates a new HTTPResponse
func (self HTTPResponse) SetCookie(key string, val string) error
SetCookie implements ResponseSetter.SetCookie
func (self HTTPResponse) SetHeader(key string, val string) error
SetHeader implements ResponseSetter.SetHeader
func (self HTTPResponse) SetRawBody(body []byte) error
func (self HTTPResponse) SetStatusCode(code int) error
SetStatusCode 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) string
ByName search Param by given name
func (ps *Params) Recycle()
Recycle the Params
func (ps *Params) Set(name string, val string) bool
Set 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