jago

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2022 License: MIT Imports: 9 Imported by: 0

README

jago

Jago is a simple go http web framework

Documentation

Index

Constants

View Source
const (
	CONNECT = http.MethodConnect
	DELETE  = http.MethodDelete
	GET     = http.MethodGet
	HEAD    = http.MethodHead
	OPTIONS = http.MethodOptions
	PATCH   = http.MethodPatch
	POST    = http.MethodPost
	// PROPFIND = "PROPFIND"
	PUT   = http.MethodPut
	TRACE = http.MethodTrace
)

HTTP methods NOTE: Deprecated, please use the stdlib constants directly instead.

View Source
const (
	MIMEApplicationJSON                  = "application/json"
	MIMEApplicationJSONCharsetUTF8       = MIMEApplicationJSON + "; " + charsetUTF8
	MIMEApplicationJavaScript            = "application/javascript"
	MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8
	MIMEApplicationXML                   = "application/xml"
	MIMEApplicationXMLCharsetUTF8        = MIMEApplicationXML + "; " + charsetUTF8
	MIMETextXML                          = "text/xml"
	MIMETextXMLCharsetUTF8               = MIMETextXML + "; " + charsetUTF8
	MIMEApplicationForm                  = "application/x-www-form-urlencoded"
	MIMEApplicationProtobuf              = "application/protobuf"
	MIMEApplicationMsgpack               = "application/msgpack"
	MIMETextHTML                         = "text/html"
	MIMETextHTMLCharsetUTF8              = MIMETextHTML + "; " + charsetUTF8
	MIMETextPlain                        = "text/plain"
	MIMETextPlainCharsetUTF8             = MIMETextPlain + "; " + charsetUTF8
	MIMEMultipartForm                    = "multipart/form-data"
	MIMEOctetStream                      = "application/octet-stream"
)

MIME types

View Source
const (

	// PROPFIND Method can be used on collection and property resources.
	PROPFIND = "PROPFIND"
	// REPORT Method can be used to get information about a resource, see rfc 3253
	REPORT = "REPORT"
	// RouteNotFound is special method type for routes handling "route not found" (404) cases
	RouteNotFound = "echo_route_not_found"
)
View Source
const (
	HeaderAccept         = "Accept"
	HeaderAcceptEncoding = "Accept-Encoding"
	// HeaderAllow is the name of the "Allow" header field used to list the set of methods
	// advertised as supported by the target resource. Returning an Allow header is mandatory
	// for status 405 (method not found) and useful for the OPTIONS method in responses.
	// See RFC 7231: https://datatracker.ietf.org/doc/html/rfc7231#section-7.4.1
	HeaderAllow               = "Allow"
	HeaderAuthorization       = "Authorization"
	HeaderContentDisposition  = "Content-Disposition"
	HeaderContentEncoding     = "Content-Encoding"
	HeaderContentLength       = "Content-Length"
	HeaderContentType         = "Content-Type"
	HeaderCookie              = "Cookie"
	HeaderSetCookie           = "Set-Cookie"
	HeaderIfModifiedSince     = "If-Modified-Since"
	HeaderLastModified        = "Last-Modified"
	HeaderLocation            = "Location"
	HeaderRetryAfter          = "Retry-After"
	HeaderUpgrade             = "Upgrade"
	HeaderVary                = "Vary"
	HeaderWWWAuthenticate     = "WWW-Authenticate"
	HeaderXForwardedFor       = "X-Forwarded-For"
	HeaderXForwardedProto     = "X-Forwarded-Proto"
	HeaderXForwardedProtocol  = "X-Forwarded-Protocol"
	HeaderXForwardedSsl       = "X-Forwarded-Ssl"
	HeaderXUrlScheme          = "X-Url-Scheme"
	HeaderXHTTPMethodOverride = "X-HTTP-Method-Override"
	HeaderXRealIP             = "X-Real-Ip"
	HeaderXRequestID          = "X-Request-Id"
	HeaderXCorrelationID      = "X-Correlation-Id"
	HeaderXRequestedWith      = "X-Requested-With"
	HeaderServer              = "Server"
	HeaderOrigin              = "Origin"
	HeaderCacheControl        = "Cache-Control"
	HeaderConnection          = "Connection"

	// Access control
	HeaderAccessControlRequestMethod    = "Access-Control-Request-Method"
	HeaderAccessControlRequestHeaders   = "Access-Control-Request-Headers"
	HeaderAccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	HeaderAccessControlAllowMethods     = "Access-Control-Allow-Methods"
	HeaderAccessControlAllowHeaders     = "Access-Control-Allow-Headers"
	HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	HeaderAccessControlExposeHeaders    = "Access-Control-Expose-Headers"
	HeaderAccessControlMaxAge           = "Access-Control-Max-Age"

	// Security
	HeaderStrictTransportSecurity         = "Strict-Transport-Security"
	HeaderXContentTypeOptions             = "X-Content-Type-Options"
	HeaderXXSSProtection                  = "X-XSS-Protection"
	HeaderXFrameOptions                   = "X-Frame-Options"
	HeaderContentSecurityPolicy           = "Content-Security-Policy"
	HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only"
	HeaderXCSRFToken                      = "X-CSRF-Token"
	HeaderReferrerPolicy                  = "Referrer-Policy"

	HttpMethodAny = "ANY"

	Version = "0.0.3"
)

Headers

Variables

View Source
var (
	ErrUnsupportedMediaType        = NewHTTPError(http.StatusUnsupportedMediaType)
	ErrNotFound                    = NewHTTPError(http.StatusNotFound)
	ErrUnauthorized                = NewHTTPError(http.StatusUnauthorized)
	ErrForbidden                   = NewHTTPError(http.StatusForbidden)
	ErrMethodNotAllowed            = NewHTTPError(http.StatusMethodNotAllowed)
	ErrStatusRequestEntityTooLarge = NewHTTPError(http.StatusRequestEntityTooLarge)
	ErrTooManyRequests             = NewHTTPError(http.StatusTooManyRequests)
	ErrBadRequest                  = NewHTTPError(http.StatusBadRequest)
	ErrBadGateway                  = NewHTTPError(http.StatusBadGateway)
	ErrInternalServerError         = NewHTTPError(http.StatusInternalServerError)
	ErrRequestTimeout              = NewHTTPError(http.StatusRequestTimeout)
	ErrServiceUnavailable          = NewHTTPError(http.StatusServiceUnavailable)
	ErrInvalidRedirectCode         = errors.New("invalid redirect status code")

	NotFoundHandler = func(c Context) error {
		return ErrNotFound
	}
)

Functions

This section is empty.

Types

type Context

type Context interface {
	Request() *http.Request
	Next() error

	Path() string
	Param(name string) string
	RealIP() string

	QueryParam(name string) string
	QueryParams() url.Values
	QueryString() string

	Cookie(name string) (*http.Cookie, error)
	Cookies() []*http.Cookie

	BindJson(i interface{}) error

	HTML(code int, html string) error
	HTMLBlob(code int, b []byte) error
	String(code int, s string) error

	JSON(code int, i interface{}) error
	JSONPretty(code int, i interface{}, indent string) error

	XML(code int, i interface{}) error
	XMLPretty(code int, i interface{}, indent string) error

	Blob(code int, contentType string, b []byte) error

	NoContent(code int) error
	Redirect(code int, url string) error
}

type Group

type Group struct {
	// contains filtered or unexported fields
}

Group is a set of sub-routes for a specified route.

func (*Group) Add

func (g *Group) Add(method, path string, handlers ...HandlerFunc)

func (*Group) Any

func (g *Group) Any(path string, handlers ...HandlerFunc)

func (*Group) Connect

func (g *Group) Connect(path string, handlers ...HandlerFunc)

func (*Group) Delete

func (g *Group) Delete(path string, handlers ...HandlerFunc)

func (*Group) Get

func (g *Group) Get(path string, handlers ...HandlerFunc)

func (*Group) Head

func (g *Group) Head(path string, handlers ...HandlerFunc)

func (*Group) Options

func (g *Group) Options(path string, handlers ...HandlerFunc)

func (*Group) Patch

func (g *Group) Patch(path string, handlers ...HandlerFunc)

func (*Group) Post

func (g *Group) Post(path string, handlers ...HandlerFunc)

func (*Group) Put

func (g *Group) Put(path string, handlers ...HandlerFunc)

func (*Group) Trace

func (g *Group) Trace(path string, handlers ...HandlerFunc)

func (*Group) Use

func (g *Group) Use(middlewares ...HandlerFunc)

type HTTPError

type HTTPError struct {
	Code    int         `json:"-"`
	Message interface{} `json:"message"`
}

func NewHTTPError

func NewHTTPError(code int, message ...interface{}) *HTTPError

func (*HTTPError) Error

func (he *HTTPError) Error() string

type HTTPErrorHandler

type HTTPErrorHandler func(error, Context)

type HandlerFunc

type HandlerFunc func(c Context) error

type Jago

type Jago struct {
	HTTPErrorHandler HTTPErrorHandler
	Debug            bool
	// contains filtered or unexported fields
}

func New

func New() *Jago

func (*Jago) Add

func (j *Jago) Add(method, path string, handlers ...HandlerFunc)

func (*Jago) Any

func (j *Jago) Any(path string, handlers ...HandlerFunc)

func (*Jago) Connect

func (j *Jago) Connect(path string, handlers ...HandlerFunc)

func (*Jago) DefaultHTTPErrorHandler

func (j *Jago) DefaultHTTPErrorHandler(err error, c Context)

func (*Jago) Delete

func (j *Jago) Delete(path string, handlers ...HandlerFunc)

func (*Jago) Get

func (j *Jago) Get(path string, handlers ...HandlerFunc)

func (*Jago) Group

func (j *Jago) Group(prefix string, handlers ...HandlerFunc) (g *Group)

func (*Jago) Head

func (j *Jago) Head(path string, handlers ...HandlerFunc)

func (*Jago) NewContext

func (j *Jago) NewContext(r *http.Request, w http.ResponseWriter) Context

func (*Jago) Options

func (j *Jago) Options(path string, handlers ...HandlerFunc)

func (*Jago) Patch

func (j *Jago) Patch(path string, handlers ...HandlerFunc)

func (*Jago) Post

func (j *Jago) Post(path string, handlers ...HandlerFunc)

func (*Jago) PrintRouter added in v0.0.2

func (j *Jago) PrintRouter()

func (*Jago) Put

func (j *Jago) Put(path string, handlers ...HandlerFunc)

func (*Jago) ServeHTTP

func (j *Jago) ServeHTTP(response http.ResponseWriter, request *http.Request)

func (*Jago) Trace

func (j *Jago) Trace(path string, handlers ...HandlerFunc)

func (*Jago) Use

func (j *Jago) Use(middlewares ...HandlerFunc)

type Mached added in v0.0.2

type Mached struct {
	// contains filtered or unexported fields
}

type Response

type Response struct {
	Writer    http.ResponseWriter
	Status    int
	Size      int64
	Committed bool
}

func NewResponse

func NewResponse(w http.ResponseWriter) (r *Response)

func (*Response) Flush

func (r *Response) Flush()

func (*Response) Header

func (r *Response) Header() http.Header

func (*Response) SetCookie

func (r *Response) SetCookie(cookie *http.Cookie)

func (*Response) SetHeader

func (r *Response) SetHeader(key string, val string)

func (*Response) Write

func (r *Response) Write(b []byte) (n int, err error)

func (*Response) WriteHeader

func (r *Response) WriteHeader(code int)

type Router

type Router struct {
	// contains filtered or unexported fields
}

func (*Router) PrintTree added in v0.0.2

func (r *Router) PrintTree()

type TreeNode added in v0.0.2

type TreeNode struct {
	// contains filtered or unexported fields
}

type Trie added in v0.0.2

type Trie struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL