rocket

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2021 License: MIT Imports: 8 Imported by: 2

README

rocket

Build Status codecov GoDoc

Rocket is a web framework inspired by rocket-rs.

Install
go get github.com/dannypsnl/rocket
Document

https://dannypsnl.github.io/rocket

Documentation

Index

Constants

View Source
const ErrorMessageForMethodNotAllowed = "request resource does not support http method '%s'"

Variables

This section is empty.

Functions

func AuthError added in v0.13.0

func AuthError(format string, a ...interface{}) *response.Response

func Delete added in v0.7.1

func Delete(route string, do interface{}) *handler

Delete return delete handler.

func Get added in v0.5.0

func Get(route string, do interface{}) *handler

Get return a get handler.

func Patch added in v0.12.0

func Patch(route string, do interface{}) *handler

Patch return a patch handler.

func Post added in v0.7.0

func Post(route string, do interface{}) *handler

Post return a post handler.

func Put added in v0.7.1

func Put(route string, do interface{}) *handler

Put return a put handler.

func ValidateError added in v0.13.0

func ValidateError(format string, a ...interface{}) *response.Response

Types

type DefaultFairing added in v1.1.0

type DefaultFairing struct{}

DefaultFairing provides default implement for your fairing by embedded it into your fairing type, Embedded is a good practice because fairing is designed to allowed partial implement interface

func (DefaultFairing) OnLaunch added in v1.1.0

func (f DefaultFairing) OnLaunch(*Rocket)

func (DefaultFairing) OnRequest added in v1.1.0

func (f DefaultFairing) OnRequest(req *http.Request) *http.Request

func (DefaultFairing) OnResponse added in v1.1.0

func (f DefaultFairing) OnResponse(resp *response.Response) *response.Response

type Fairing added in v0.14.0

type Fairing interface {
	OnRequest(*http.Request) *http.Request
	OnResponse(*response.Response) *response.Response
	// OnLaunch would let you could get the metadata of rocket server
	//
	// NOTE: only work when you using `Launch()` to start server
	// won't work while you use rocket as HTTP handler
	OnLaunch(*Rocket)
}

Fairing specify the method that fairing could implement

type Guard added in v0.13.0

type Guard interface {
	VerifyRequest() *response.Response
}

Guard is an interface that context can implement, when context implement this, context can reject request with a *response.Response.

type Rocket

type Rocket struct {

	// MultiFormBodySizeLimit decide the multiple forms value size
	MultiFormBodySizeLimit int64
	// contains filtered or unexported fields
}

Rocket is our service.

func Ignite

func Ignite(port int) *Rocket

Ignite initial service by port.

func (*Rocket) Attach added in v0.12.7

func (rk *Rocket) Attach(f Fairing) *Rocket

Attach add fairing to lifecycle for each request and response

func (*Rocket) Default added in v0.12.0

func (rk *Rocket) Default(do interface{}) *Rocket

Default receive a function that have signature `func() <T>` for custom response when no route matched, <T> means a legal response Type of rocket, e.g. `*response.Response`, `response.Json` by default that(status code 404) would returns `"page not found"` when no set this function,

func (*Rocket) EnableHTTPs added in v0.14.0

func (rk *Rocket) EnableHTTPs(certFile, keyFile string) *Rocket

EnableHTTPs would get certFile and keyFile to enable HTTPs

func (*Rocket) Launch

func (rk *Rocket) Launch()

Launch shoot our service.(start server)

func (*Rocket) Mount

func (rk *Rocket) Mount(handlers ...*handler) *Rocket

Mount add handlers into our service.

func (*Rocket) OnClose added in v1.1.0

func (rk *Rocket) OnClose(f func() error) *Rocket

OnClose takes a function f and runs it after server closed

func (*Rocket) ServeHTTP added in v0.2.1

func (rk *Rocket) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is prepare for http server trait, so that you could use `*rocket.Rocket` as `http.Handler`

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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