fin

package module
v0.0.0-...-5167af4 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2017 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DELETE  = "DELETE"
	GET     = "GET"
	HEAD    = "HEAD"
	OPTIONS = "OPTIONS"
	PATCH   = "PATCH"
	POST    = "POST"
	PUT     = "PUT"
)

HTTP methods

Variables

View Source
var (
	ErrUnsupportedMediaType        = NewHTTPError(status.UnsupportedMediaType)
	ErrNotFound                    = NewHTTPError(status.NotFound)
	ErrUnauthorized                = NewHTTPError(status.Unauthorized)
	ErrForbidden                   = NewHTTPError(status.Forbidden)
	ErrMethodNotAllowed            = NewHTTPError(status.MethodNotAllowed)
	ErrStatusRequestEntityTooLarge = NewHTTPError(status.RequestEntityTooLarge)
	ErrInternalServer              = NewHTTPError(status.InternalServerError)
	ErrValidatorNotRegistered      = errors.New("Validator not registered")
	ErrRendererNotRegistered       = errors.New("Renderer not registered")
	ErrInvalidRedirectCode         = errors.New("Invalid redirect status code")
	ErrCookieNotFound              = errors.New("Cookie not found")
)

Errors

View Source
var (
	// NotFoundHandler run if not match registerd method and path.
	NotFoundHandler = func(c Context) error {
		return ErrNotFound
	}

	// MethodNotAllowedHandler run if not match registerd method.
	MethodNotAllowedHandler = func(c Context) error {
		return ErrMethodNotAllowed
	}
)
View Source
var (
	LogDir  = "log"
	LogName = "fin_log"
)

Functions

This section is empty.

Types

type Context

type Context interface {
	Path() string
	SetPath(string)

	Request() *http.Request
	SetRequest(*http.Request)
	Response() *Response

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

	Params() httprouter.Params
	FormValue(string) string
	FormParams() (url.Values, error)

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

	Handler() HandlerFunc
	SetHandler(HandlerFunc)

	Error(error)

	Get(interface{}) interface{}
	Set(interface{}, interface{})

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

	Logger() *zap.Logger
	Render(tmpl string, vars xslate.Vars) error

	SetContentType(code int, contentType string)
	JSON(code int, i interface{}) error
	XML(code int, i interface{}) error
	String(code int, content string) error
}

type Engine

type Engine struct {
	*zap.Logger
	*xslate.Xslate
	Port             int
	Server           *http.Server
	HTTPErrorHandler func(error, Context)
	// contains filtered or unexported fields
}

Engine is context for this application

func New

func New() *Engine

New return the context for vegeta application

func (*Engine) CreateContext

func (e *Engine) CreateContext(w http.ResponseWriter, r *http.Request, params Params) Context

func (*Engine) DELETE

func (e *Engine) DELETE(path string, f HandlerFunc)

DELETE registers a new DELETE route for a path with matching handler into the httprouter with optional handler-level middleware.

func (*Engine) DefaultHTTPErrorHandler

func (e *Engine) DefaultHTTPErrorHandler(err error, c Context)

DefaultHTTPErrorHandler render error message to response

func (*Engine) Find

func (e *Engine) Find(method, path string, c Context) (valid bool)

Find lookup a handler registered for method and path. It also parses URL for path parameters and load them into context.

func (*Engine) GET

func (e *Engine) GET(path string, f HandlerFunc)

GET registers a new GET route for a path with matching handler into the httprouter with optional handler-level middleware.

func (*Engine) HEAD

func (e *Engine) HEAD(path string, f HandlerFunc)

HEAD registers a new HEAD route for a path with matching handler into the httprouter with optional handler-level middleware.

func (*Engine) Handle

func (e *Engine) Handle(method, path string, handler HandlerFunc)

Handle registers a your specified a path and method into httprouter with optional handler-level middleware.

func (*Engine) Listen

func (e *Engine) Listen() (net.Listener, error)

func (*Engine) Lookup

func (e *Engine) Lookup(method, path string) (HandlerFunc, Params)

Lookup a handler registerd for method and path. It returns path parameters and HandlerFunc or nil HandlerFunc

func (*Engine) NewContext

func (e *Engine) NewContext(w http.ResponseWriter, r *http.Request) Context

NewContext returns a Context instance.

func (*Engine) OPTIONS

func (e *Engine) OPTIONS(path string, f HandlerFunc)

OPTIONS registers a new OPTIONS route for a path with matching handler into the httprouter with optional handler-level middleware.

func (*Engine) PATCH

func (e *Engine) PATCH(path string, f HandlerFunc)

PATCH registers a new PATCH route for a path with matching handler into the httprouter with optional handler-level middleware.

func (*Engine) POST

func (e *Engine) POST(path string, f HandlerFunc)

POST registers a new POST route for a path with matching handler into the httprouter with optional handler-level middleware.

func (*Engine) PUT

func (e *Engine) PUT(path string, f HandlerFunc)

PUT registers a new PUT route for a path with matching handler into the httprouter with optional handler-level middleware.

func (*Engine) ReUseContext

func (e *Engine) ReUseContext(c Context)

func (*Engine) Serve

func (e *Engine) Serve(ctx context.Context) error

func (*Engine) ServeHTTP

func (e *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Engine) Shutdown

func (e *Engine) Shutdown(ctx context.Context) error

func (*Engine) Start

func (e *Engine) Start(ctx context.Context) error

func (*Engine) UseMiddleWare

func (e *Engine) UseMiddleWare(middleware ...MiddlewareFunc)

UseMiddleWare registers middleware handlers before run registered matching handler.

type HTTPError

type HTTPError struct {
	Code    int
	Message string
}

HTTPError represents an error that occurred while handling a request.

func NewHTTPError

func NewHTTPError(code int, message ...string) *HTTPError

NewHTTPError creates a new HTTPError instance.

func (*HTTPError) Error

func (he *HTTPError) Error() string

Error makes it compatible with `error` interface.

type HandlerFunc

type HandlerFunc func(Context) error

HandlerFunc defines a function to server HTTP requests.

type Map

type Map = *sync.Map

Map is alias of *sync.Map

type MiddlewareFunc

type MiddlewareFunc func(HandlerFunc) HandlerFunc

MiddlewareFunc defines a function to server HTTP requests.

type Params

type Params = httprouter.Params

Params is alias of httprouter.Params

type Response

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

func NewResponse

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

NewResponse creates a new instance of Response.

func (*Response) CloseNotify

func (r *Response) CloseNotify() <-chan bool

CloseNotify implements the http.CloseNotifier interface to allow detecting when the underlying connection has gone away. This mechanism can be used to cancel long operations on the server if the client has disconnected before the response is ready. See http.CloseNotifier(https://golang.org/pkg/net/http/#CloseNotifier)

func (*Response) Flush

func (r *Response) Flush()

Flush implements the http.Flusher interface to allow an HTTP handler to flush buffered data to the client. See http.Flusher(https://golang.org/pkg/net/http/#Flusher)

func (*Response) Header

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

Header returns the header map for the writer that will be sent by WriteHeader. Changing the header after a call to WriteHeader (or Write) has no effect unless the modified headers were declared as trailers by setting the "Trailer" header before the call to WriteHeader (see example) To suppress implicit response headers, set their value to nil. Example: https://golang.org/pkg/net/http/#example_ResponseWriter_trailers

func (*Response) Hijack

func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error)

Hijack implements the http.Hijacker interface to allow an HTTP handler to take over the connection. See http.Hijacker(https://golang.org/pkg/net/http/#Hijacker)

func (*Response) Write

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

func (*Response) WriteHeader

func (r *Response) WriteHeader(code int)

type Vars

type Vars = xslate.Vars

Vars is alias of xslate.Vars

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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