Documentation ¶
Index ¶
- Constants
- Variables
- func EnableDebug(b bool)
- func GetJSON(path string, result interface{}) error
- func GetStream(path string) (io.ReadCloser, error)
- func GetText(path string) (string, error)
- func Params(r *http.Request) map[string]string
- func PatchJSON(path string, body interface{}, result interface{}) error
- func PostJSON(path string, body interface{}, result interface{}) error
- func PutJSON(path string, body interface{}, result interface{}) error
- func SaveFile(path string, filename string) error
- func SetLogger(l Logger)
- func StatusText(code int) string
- type Builder
- func (b *Builder) Build() *Template
- func (b *Builder) CleanBody() *Builder
- func (b *Builder) CleanHeaders() *Builder
- func (b *Builder) CleanQueries() *Builder
- func (b *Builder) Client(client *http.Client) *Builder
- func (b *Builder) Delete(path string) *Builder
- func (b *Builder) Do(client ...*http.Client) *Response
- func (b *Builder) Get(path string) *Builder
- func (b *Builder) Header(k, v string) *Builder
- func (b *Builder) Headers(m map[string]string) *Builder
- func (b *Builder) Options(path string) *Builder
- func (b *Builder) Patch(path string) *Builder
- func (b *Builder) Post(path string) *Builder
- func (b *Builder) Prefix(p string) *Builder
- func (b *Builder) Put(path string) *Builder
- func (b *Builder) Queries(m map[string]string) *Builder
- func (b *Builder) Query(k, v string) *Builder
- func (b *Builder) Write(reader io.Reader) *Builder
- func (b *Builder) WriteFile(filename string) *Builder
- func (b *Builder) WriteFormFile(formName string, fileName string) *Builder
- func (b *Builder) WriteJSON(v interface{}) *Builder
- func (b *Builder) WriteText(text string) *Builder
- func (b *Builder) WriteXML(v interface{}) *Builder
- type EntryView
- type HandlerFunc
- type Logger
- type Middleware
- type Request
- func (r *Request) AddCooke(cookie *http.Cookie)
- func (r *Request) BasicAuth() (username string, password string, ok bool)
- func (r *Request) BindForm(i interface{}) error
- func (r *Request) BindJSON(i interface{}) error
- func (r *Request) BindPostForm(i interface{}) error
- func (r *Request) BindQuery(i interface{}) error
- func (r *Request) BindXML(i interface{}) error
- func (r *Request) Context() context.Context
- func (r *Request) Cookie(key string) (string, error)
- func (r *Request) CookieExists(key string) bool
- func (r *Request) CookieOrDefault(key string, defaultValue ...string) string
- func (r *Request) Form(key string) string
- func (r *Request) FormExists(key string) bool
- func (r *Request) Header(key string) string
- func (r *Request) HeaderExists(key string) bool
- func (r *Request) HeaderOrDefault(key string, value string) string
- func (r *Request) Method() string
- func (r *Request) Param(key string) string
- func (r *Request) ParamExists(key string) bool
- func (r *Request) ParamOrDefault(key string, value string) string
- func (r *Request) Path() string
- func (r *Request) PostForm(key string) string
- func (r *Request) PostFormExists(key string) bool
- func (r *Request) Query(key string) string
- func (r *Request) QueryExists(key string) bool
- func (r *Request) QueryOrDefault(key string, value string) string
- func (r *Request) Raw() *http.Request
- func (r *Request) SetBasicAuth(username string, password string)
- func (r *Request) SetContext(ctx context.Context)
- func (r *Request) SetHeader(key string, value string)
- type Response
- func Get(path string) *Response
- func Patch(path string, reader io.Reader, contentType string) *Response
- func Post(path string, reader io.Reader, contentType string) *Response
- func PostFile(path string, fileName string) *Response
- func PostFormFile(path string, formName string, fileName string) *Response
- func Put(path string, reader io.Reader, contentType string) *Response
- func WrapResponse(r *http.Response) *Response
- func (r *Response) Bytes() ([]byte, error)
- func (r *Response) Dump(body bool) ([]byte, error)
- func (r *Response) JSON(value interface{}) error
- func (r *Response) Pipe(writer io.Writer) error
- func (r *Response) SaveFile(filename string) error
- func (r *Response) StatusCode() int
- func (r *Response) Stream() (io.ReadCloser, error)
- func (r *Response) Text() (string, error)
- func (r *Response) XML(value interface{}) error
- type ResponseWriter
- func (w *ResponseWriter) HTML(statusCode int, content string)
- func (w *ResponseWriter) Header(key string, value string) *ResponseWriter
- func (w *ResponseWriter) JSON(statusCode int, value interface{})
- func (w *ResponseWriter) Raw() http.ResponseWriter
- func (w *ResponseWriter) StatusCode(statusCode int)
- func (w *ResponseWriter) Text(statusCode int, text string)
- func (w *ResponseWriter) XML(statusCode int, value interface{})
- type Router
- func (router *Router) Any(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router
- func (router *Router) Delete(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router
- func (router *Router) Get(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router
- func (router *Router) Group(prefix string, middlewares ...Middleware) *group
- func (router *Router) Handle(method string, path string, handler HandlerFunc, middlewares ...Middleware) *Router
- func (router *Router) HandleNotFound(h HandlerFunc) *Router
- func (router *Router) Items() []EntryView
- func (router *Router) Options(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router
- func (router *Router) Patch(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router
- func (router *Router) Post(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router
- func (router *Router) Prefix(p string) *Router
- func (router *Router) Put(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router
- func (router *Router) Run(addr string) error
- func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (router *Router) String() string
- func (router *Router) Use(middlewares ...Middleware) *Router
- type Template
Examples ¶
Constants ¶
View Source
const ( StatusContinue = http.StatusContinue StatusSwitchingProtocols = http.StatusSwitchingProtocols StatusProcessing = http.StatusProcessing StatusEarlyHints = http.StatusEarlyHints StatusOK = http.StatusOK StatusCreated = http.StatusCreated StatusAccepted = http.StatusAccepted StatusNonAuthoritativeInfo = http.StatusNonAuthoritativeInfo StatusNoContent = http.StatusNoContent StatusResetContent = http.StatusResetContent StatusPartialContent = http.StatusPartialContent StatusMultiStatus = http.StatusMultiStatus StatusAlreadyReported = http.StatusAlreadyReported StatusIMUsed = http.StatusIMUsed StatusMultipleChoices = http.StatusMultipleChoices StatusMovedPermanently = http.StatusMovedPermanently StatusFound = http.StatusFound StatusSeeOther = http.StatusSeeOther StatusNotModified = http.StatusNotModified StatusUseProxy = http.StatusUseProxy StatusTemporaryRedirect = http.StatusTemporaryRedirect StatusPermanentRedirect = http.StatusPermanentRedirect StatusBadRequest = http.StatusBadRequest StatusPaymentRequired = http.StatusPaymentRequired StatusForbidden = http.StatusForbidden StatusNotFound = http.StatusNotFound StatusMethodNotAllowed = http.StatusMethodNotAllowed StatusNotAcceptable = http.StatusNotAcceptable StatusProxyAuthRequired = http.StatusProxyAuthRequired StatusRequestTimeout = http.StatusRequestTimeout StatusConflict = http.StatusConflict StatusGone = http.StatusGone StatusLengthRequired = http.StatusLengthRequired StatusPreconditionFailed = http.StatusPreconditionFailed StatusRequestEntityTooLarge = http.StatusRequestEntityTooLarge StatusRequestURITooLong = http.StatusRequestURITooLong StatusUnsupportedMediaType = http.StatusUnsupportedMediaType StatusRequestedRangeNotSatisfiable = http.StatusRequestedRangeNotSatisfiable StatusExpectationFailed = http.StatusExpectationFailed StatusTeapot = http.StatusTeapot StatusMisdirectedRequest = http.StatusMisdirectedRequest StatusUnprocessableEntity = http.StatusUnprocessableEntity StatusLocked = http.StatusLocked StatusFailedDependency = http.StatusFailedDependency StatusTooEarly = http.StatusTooEarly StatusUpgradeRequired = http.StatusUpgradeRequired StatusPreconditionRequired = http.StatusPreconditionRequired StatusTooManyRequests = http.StatusTooManyRequests StatusRequestHeaderFieldsTooLarge = http.StatusRequestHeaderFieldsTooLarge StatusInternalServerError = http.StatusInternalServerError StatusNotImplemented = http.StatusNotImplemented StatusBadGateway = http.StatusBadGateway StatusGatewayTimeout = http.StatusGatewayTimeout StatusHTTPVersionNotSupported = http.StatusHTTPVersionNotSupported StatusVariantAlsoNegotiates = http.StatusVariantAlsoNegotiates StatusInsufficientStorage = http.StatusInsufficientStorage StatusLoopDetected = http.StatusLoopDetected StatusNotExtended = http.StatusNotExtended StatusNetworkAuthenticationRequired = http.StatusNetworkAuthenticationRequired )
Variables ¶
View Source
var ( ErrOpenFileFailed = errorf("open file failed") ErrTemplateRequireURL = errorf("template require url") ErrTemplateRequireMethod = errorf("template require method") )
View Source
var ( ErrResponseBodyHasRead = errorf("http: response body has read") ErrUnknownError = errorf("http: unknown error") )
Functions ¶
func EnableDebug ¶
func EnableDebug(b bool)
func StatusText ¶
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func NewBuilder ¶
func (*Builder) CleanHeaders ¶
func (*Builder) CleanQueries ¶
func (*Builder) WriteFormFile ¶
type HandlerFunc ¶
type HandlerFunc func(w *ResponseWriter, r *Request)
func (HandlerFunc) Next ¶
func (h HandlerFunc) Next(w *ResponseWriter, r *Request)
func (HandlerFunc) ServeHTTP ¶
func (h HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Middleware ¶
type Middleware = func(HandlerFunc) HandlerFunc
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func WrapRequest ¶
func (*Request) BindPostForm ¶
func (*Request) CookieExists ¶
func (*Request) CookieOrDefault ¶
func (*Request) FormExists ¶
func (*Request) HeaderExists ¶
func (*Request) HeaderOrDefault ¶
func (*Request) ParamExists ¶
func (*Request) PostFormExists ¶
func (*Request) QueryExists ¶
func (*Request) SetBasicAuth ¶
func (*Request) SetContext ¶
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
func WrapResponse ¶
func (*Response) StatusCode ¶
type ResponseWriter ¶
type ResponseWriter struct {
// contains filtered or unexported fields
}
func WrapResponseWriter ¶
func WrapResponseWriter(w http.ResponseWriter) *ResponseWriter
func (*ResponseWriter) HTML ¶
func (w *ResponseWriter) HTML(statusCode int, content string)
func (*ResponseWriter) Header ¶
func (w *ResponseWriter) Header(key string, value string) *ResponseWriter
func (*ResponseWriter) JSON ¶
func (w *ResponseWriter) JSON(statusCode int, value interface{})
func (*ResponseWriter) Raw ¶
func (w *ResponseWriter) Raw() http.ResponseWriter
func (*ResponseWriter) StatusCode ¶
func (w *ResponseWriter) StatusCode(statusCode int)
func (*ResponseWriter) Text ¶
func (w *ResponseWriter) Text(statusCode int, text string)
func (*ResponseWriter) XML ¶
func (w *ResponseWriter) XML(statusCode int, value interface{})
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func NewRouter ¶
func NewRouter(middlewares ...Middleware) *Router
func (*Router) Any ¶
func (router *Router) Any(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router
func (*Router) Delete ¶
func (router *Router) Delete(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router
func (*Router) Get ¶
func (router *Router) Get(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router
func (*Router) Group ¶
func (router *Router) Group(prefix string, middlewares ...Middleware) *group
func (*Router) Handle ¶
func (router *Router) Handle(method string, path string, handler HandlerFunc, middlewares ...Middleware) *Router
func (*Router) HandleNotFound ¶
func (router *Router) HandleNotFound(h HandlerFunc) *Router
func (*Router) Options ¶
func (router *Router) Options(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router
func (*Router) Patch ¶
func (router *Router) Patch(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router
func (*Router) Post ¶
func (router *Router) Post(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router
func (*Router) Put ¶
func (router *Router) Put(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router
func (*Router) Use ¶
func (router *Router) Use(middlewares ...Middleware) *Router
type Template ¶
type Template struct { Client *http.Client Prefix string Method string Path string Queries map[string]string Headers map[string]string Body io.Reader }
func (*Template) New ¶
Example ¶
t := &Template{ Prefix: "https://example.com/", Queries: map[string]string{ "foo": "bar", }, } fmt.Println(t.FullURL()) fmt.Println(t.New().Get("/user").Query("id", "1").Queries(map[string]string{"name": "medivh"}).Build().FullURL())
Output: https://example.com/?foo=bar https://example.com/user?foo=bar&id=1&name=medivh
Source Files ¶
Click to show internal directories.
Click to hide internal directories.