Documentation
¶
Index ¶
- Constants
- type Binder
- type Context
- type Group
- func (g *Group) Connect(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *Group) Delete(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *Group) Get(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *Group) Group(path string, middlewares ...MiddlewareFunc) *Group
- func (g *Group) Head(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *Group) Options(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *Group) Patch(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *Group) Post(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *Group) Put(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *Group) Use(middlewares ...MiddlewareFunc)
- type HTTPError
- type HandlerFunc
- type Harmony
- func (h *Harmony) Connect(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (h *Harmony) Delete(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (h *Harmony) Get(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (h *Harmony) GracefulShutdown() error
- func (h *Harmony) Group(path string, middlewares ...MiddlewareFunc) *Group
- func (h *Harmony) Head(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (h *Harmony) ListenAndServe(port ...int) error
- func (h *Harmony) Options(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (h *Harmony) Patch(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (h *Harmony) Post(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (h *Harmony) Put(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (h *Harmony) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (h *Harmony) Trace(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
- func (h *Harmony) Use(middlewares ...MiddlewareFunc)
- type Map
- type MiddlewareFunc
Constants ¶
const ( // HeaderContentType is the header key for Content-Type. HeaderContentType = "Content-Type" // HeaderVary is the header key for Vary. HeaderVary = "Vary" // HeaderAcceptEncoding is the header key for Accept-Encoding. HeaderAcceptEncoding = "Accept-Encoding" // HeaderContentLength is the header key for Content-Length. HeaderContentLength = "Content-Length" // HeaderContentEncoding is the header key for Content-Encoding. HeaderContentEncoding = "Content-Encoding" )
const ( // MIMEApplicationJSON is the MIME type for JSON. MIMEApplicationJSON = "application/json" // MIMEApplicationJSONCharsetUTF8 is the MIME type for JSON with charset=utf-8. MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8 // MIMETextPlain is the MIME type for plain text. MIMETextPlain = "text/plain" // MIMETextPlainCharsetUTF8 is the MIME type for plain text with charset=utf-8. MIMETextPlainCharsetUTF8 = MIMETextPlain + "; " + charsetUTF8 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Binder ¶
type Binder interface { // Bind binds the request body, path params and query params to the dest. Bind(ctx Context, dest any) error // BindJSON binds the request body to the dest. BindJSON(ctx Context, dest any) error }
Binder is the interface that wraps the Bind and BindJSON method.
type Context ¶
type Context interface { // Request returns the *http.Request object. Request() *http.Request // ResponseWriter returns the http.ResponseWriter object. ResponseWriter() http.ResponseWriter // Bind binds the request body into dest. Bind(dest any) error // JSON writes the response in JSON format. JSON(code int, body any) error // PathParams returns the path parameters of the request in map[string]string. PathParams() map[string]string // PathParam returns the path parameter of the request by key in string. PathParam(key string) string // PathParamInt returns the path parameter of the request by key in int. // If the value is not an integer, it will return an error. // Handle the error like strconv.Atoi. PathParamInt(key string) (int, error) // SetPathParam sets the path parameter of the request by key and value. SetPathParam(key, value string) // QueryString returns the query string of the request in string. QueryString(key string, defaultValue ...string) string // QueryInt returns the query parameter of the request by key in int. QueryInt(key string, defaultValue ...int) int // QueryFloat64 returns the query parameter of the request by key in float64. QueryFloat64(key string, defaultValue ...float64) float64 // QueryBool returns the query parameter of the request by key in bool. QueryBool(key string, defaultValue ...bool) bool // SendStatus writes the response status code. SendStatus(code int) error // String writes the response in string format. String(code int, body string) error // Get returns the value in the context by key. Get(key string) any // Set sets the value in the context by key and value. Set(key string, value any) // SetResponseWriter sets the http.ResponseWriter. SetResponseWriter(w http.ResponseWriter) // contains filtered or unexported methods }
Context is the interface for the Harmony context.
func NewContext ¶
NewContext returns a new Harmony Context.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is the interface for Harmony's Group.
func (*Group) Connect ¶
func (g *Group) Connect(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Connect adds a CONNECT route to Harmony's Group.
func (*Group) Delete ¶
func (g *Group) Delete(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Delete adds a DELETE route to Harmony's Group.
func (*Group) Get ¶
func (g *Group) Get(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Get adds a GET route to Harmony's Group.
func (*Group) Group ¶
func (g *Group) Group(path string, middlewares ...MiddlewareFunc) *Group
Group creates a new Harmony subgroup in the current group
func (*Group) Head ¶
func (g *Group) Head(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Head adds a HEAD route to Harmony's Group.
func (*Group) Options ¶
func (g *Group) Options(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Options adds an OPTIONS route to Harmony's Group.
func (*Group) Patch ¶
func (g *Group) Patch(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Patch adds a PATCH route to Harmony's Group.
func (*Group) Post ¶
func (g *Group) Post(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Post adds a POST route to Harmony.
func (*Group) Put ¶
func (g *Group) Put(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Put adds a PUT route to Harmony's Group.
func (*Group) Use ¶
func (g *Group) Use(middlewares ...MiddlewareFunc)
Use adds middlewares to the group.
type HTTPError ¶
HTTPError is the error returned by Harmony.
func NewHTTPError ¶
NewHTTPError returns a new HTTP error.
type HandlerFunc ¶
HandlerFunc is the function signature used by all Harmony handlers.
type Harmony ¶
type Harmony struct {
// contains filtered or unexported fields
}
Harmony is the interface for Harmony.
func (*Harmony) Connect ¶
func (h *Harmony) Connect(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Connect adds a CONNECT route to Harmony.
func (*Harmony) Delete ¶
func (h *Harmony) Delete(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Delete adds a DELETE route to Harmony.
func (*Harmony) Get ¶
func (h *Harmony) Get(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Get adds a GET route to Harmony.
func (*Harmony) GracefulShutdown ¶
GracefulShutdown waits for SIGINT and gracefully shutdown the server.
func (*Harmony) Group ¶
func (h *Harmony) Group(path string, middlewares ...MiddlewareFunc) *Group
Group creates a new Harmony group.
func (*Harmony) Head ¶
func (h *Harmony) Head(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Head adds a HEAD route to Harmony.
func (*Harmony) ListenAndServe ¶
ListenAndServe starts the server.
func (*Harmony) Options ¶
func (h *Harmony) Options(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Options adds an OPTIONS route to Harmony.
func (*Harmony) Patch ¶
func (h *Harmony) Patch(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Patch adds a PATCH route to Harmony.
func (*Harmony) Post ¶
func (h *Harmony) Post(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Post adds a POST route to Harmony.
func (*Harmony) Put ¶
func (h *Harmony) Put(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Put adds a PUT route to Harmony.
func (*Harmony) ServeHTTP ¶
func (h *Harmony) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler.
func (*Harmony) Trace ¶
func (h *Harmony) Trace(path string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc)
Trace adds a TRACE route to Harmony.
func (*Harmony) Use ¶
func (h *Harmony) Use(middlewares ...MiddlewareFunc)
Use adds a middleware to Harmony.
type MiddlewareFunc ¶
type MiddlewareFunc func(next HandlerFunc) HandlerFunc
MiddlewareFunc is the function signature used by all Harmony middlewares.