Documentation ¶
Index ¶
- Constants
- Variables
- func HTTPMethod(ctx context.Context) string
- func MultipartForm(ctx context.Context) *multipart.Form
- func Run(port int) error
- func RunElegant(port int, timeout time.Duration) error
- func RunTLS(port int, cert, key string) error
- func RunTLSElegant(port int, timeout time.Duration, cert, key string) error
- func ServeFile(path, dir string)
- type APIBuilder
- func (b *APIBuilder) Class(c string) *APIBuilder
- func (b *APIBuilder) Done()
- func (b *APIBuilder) Get() *APIBuilder
- func (b *APIBuilder) Handle(h Handler) *APIBuilder
- func (b *APIBuilder) HandleFunc(f func(ctx context.Context) interface{}) *APIBuilder
- func (b *APIBuilder) Post() *APIBuilder
- func (b *APIBuilder) Version(v string) *APIBuilder
- func (b *APIBuilder) With(handlers ...negroni.Handler) *APIBuilder
- type ContextKey
- type Handler
- type HandlerFunc
Constants ¶
const ( ContentType = "Content-Type" ApplicationJSON = "application/json" MultipartFormData = "multipart/form-data" AcceptLanguage = "Accept-Language" Authorization = "Authorization" UserAgent = "User-Agent" AllowOrigin = "Access-Control-Allow-Origin" )
definitions for HTTP headers.
Variables ¶
var ( // JSONMiddle checks whether it is a JSON request. JSONMiddle = negroni.HandlerFunc(jsonMiddleware) // MultipartFormMiddle checks whether it is a multipart/form-data request. MultipartFormMiddle = negroni.HandlerFunc(multipartFormMiddleware) // CORSMiddle handle CORS request, see https://github.com/rs/cors CORSMiddle = negroni.HandlerFunc(corsMiddleware) // RecoverPanicMiddle recovers and records the stack info when panic occurred. // This prevents web server from crashing. RecoverPanicMiddle = negroni.HandlerFunc(recoverPanicMiddleWare) // LoggerMiddle adds statistic information for every request. LoggerMiddle = negroni.HandlerFunc(loggerMiddleware) )
Functions ¶
func HTTPMethod ¶
HTTPMethod returns the HTTP method of request associated in Context.
func MultipartForm ¶
MultipartForm returns the multipart form data associated in Context.
func RunElegant ¶
RunElegant starts a web server which can be shutdown gracefully with a timout.
func RunTLSElegant ¶
RunTLSElegant starts a TLS-based web server which can be shutdown gracefully with a timeout.
Types ¶
type APIBuilder ¶
type APIBuilder struct {
// contains filtered or unexported fields
}
APIBuilder is responsible for building APIs. Please don't operate it directly, use chaining calls instead.
func (*APIBuilder) Class ¶
func (b *APIBuilder) Class(c string) *APIBuilder
Class defines the API class.
func (*APIBuilder) Done ¶
func (b *APIBuilder) Done()
Done triggers APIBuilder to build and register an API.
func (*APIBuilder) Handle ¶
func (b *APIBuilder) Handle(h Handler) *APIBuilder
Handle defines the handler of request.
func (*APIBuilder) HandleFunc ¶
func (b *APIBuilder) HandleFunc(f func(ctx context.Context) interface{}) *APIBuilder
HandleFunc defines the handler function of request.
func (*APIBuilder) Post ¶
func (b *APIBuilder) Post() *APIBuilder
Post marks API an HTTP POST request.
func (*APIBuilder) Version ¶
func (b *APIBuilder) Version(v string) *APIBuilder
Version defines the API version.
func (*APIBuilder) With ¶
func (b *APIBuilder) With(handlers ...negroni.Handler) *APIBuilder
With adds a series of middleware plugins to the API.
type HandlerFunc ¶
HandlerFunc is an adapter to allow the use of ordinary functions as handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f.
func (HandlerFunc) Handle ¶
func (hf HandlerFunc) Handle(ctx context.Context) interface{}
Handle calls HandlerFunc itself.