deer

package module
v0.0.65 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: MIT Imports: 17 Imported by: 0

README

Deer

A go language http library using decorators.

Why Deer

Lightweight, lower dependence and efficient.

Quick Start

package main

import (
	"log"
	"net/http"

	"github.com/medivhyang/deer"
)

func main() {
	deer.Debug(true)

	r := deer.Default()

	r.Get("/", func(w deer.ResponseWriter, r *deer.Request) {
		w.Text(http.StatusOK, "hello world")
	})

	log.Fatalln(r.Run(":8080"))
}

More examples references /examples directory.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrResponseBodyHasRead = newError("http response", "body has read")

Functions

func Debug added in v0.0.58

func Debug(b bool)

func Output added in v0.0.61

func Output(writer io.Writer)

func Params added in v0.0.41

func Params(r *http.Request) map[string]string

Types

type CORSOptions added in v0.0.60

type CORSOptions struct {
	AllowOrigins     []string
	AllowMethods     []string
	AllowHeaders     []string
	ExposeHeaders    []string
	AllowCredentials bool
}

type EntryView added in v0.0.58

type EntryView struct {
	Method  string `json:"method"`
	Pattern string `json:"pattern"`
}

type HandlerFunc

type HandlerFunc func(w ResponseWriter, r *Request)

func (HandlerFunc) Next added in v0.0.35

func (h HandlerFunc) Next(w ResponseWriter, r *Request)

func (HandlerFunc) ServeHTTP

func (h HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Middleware

type Middleware = func(HandlerFunc) HandlerFunc

func AllowedMethods added in v0.0.60

func AllowedMethods(methods ...string) Middleware

func BasicAuth added in v0.0.60

func BasicAuth(pairs map[string]string, realm ...string) Middleware

func BasicAuthWithFunc added in v0.0.60

func BasicAuthWithFunc(f func(username, password string) bool, realm ...string) Middleware

func CORS added in v0.0.60

func CORS(config ...CORSOptions) Middleware

func MaxAllowed added in v0.0.60

func MaxAllowed(n int) Middleware

func Recovery added in v0.0.60

func Recovery(callback ...func(w ResponseWriter, r *Request, err interface{})) Middleware

func Timing added in v0.0.60

func Timing(callback ...func(w ResponseWriter, r *Request, d time.Duration)) Middleware

func Trace added in v0.0.60

func Trace(callback ...func(w ResponseWriter, r *Request)) Middleware

type Request added in v0.0.3

type Request struct {
	Raw *http.Request
	// contains filtered or unexported fields
}

func WrapRequest

func WrapRequest(r *http.Request) *Request

func (*Request) AddCooke added in v0.0.58

func (r *Request) AddCooke(cookie *http.Cookie)

func (*Request) BasicAuth added in v0.0.35

func (r *Request) BasicAuth() (username string, password string, ok bool)

func (*Request) BindForm added in v0.0.58

func (r *Request) BindForm(i interface{}) error

func (*Request) BindJSON added in v0.0.58

func (r *Request) BindJSON(i interface{}) error

func (*Request) BindPostForm added in v0.0.58

func (r *Request) BindPostForm(i interface{}) error

func (*Request) BindQuery added in v0.0.58

func (r *Request) BindQuery(i interface{}) error

func (*Request) BindXML added in v0.0.58

func (r *Request) BindXML(i interface{}) error

func (*Request) Context added in v0.0.11

func (r *Request) Context() context.Context

func (*Request) Cookie added in v0.0.35

func (r *Request) Cookie(key string) (string, error)

func (*Request) CookieExists added in v0.0.58

func (r *Request) CookieExists(key string) bool

func (*Request) CookieOrDefault added in v0.0.35

func (r *Request) CookieOrDefault(key string, defaultValue ...string) string

func (*Request) Form added in v0.0.3

func (r *Request) Form(key string) string

func (*Request) FormExists added in v0.0.3

func (r *Request) FormExists(key string) bool

func (*Request) Header added in v0.0.3

func (r *Request) Header(key string) string

func (*Request) HeaderExists added in v0.0.58

func (r *Request) HeaderExists(key string) bool

func (*Request) HeaderOrDefault added in v0.0.20

func (r *Request) HeaderOrDefault(key string, value string) string

func (*Request) Method added in v0.0.3

func (r *Request) Method() string

func (*Request) Param added in v0.0.41

func (r *Request) Param(key string) string

func (*Request) ParamExists added in v0.0.58

func (r *Request) ParamExists(key string) bool

func (*Request) ParamOrDefault added in v0.0.41

func (r *Request) ParamOrDefault(key string, value string) string

func (*Request) Path added in v0.0.3

func (r *Request) Path() string

func (*Request) PostForm added in v0.0.20

func (r *Request) PostForm(key string) string

func (*Request) PostFormExists added in v0.0.58

func (r *Request) PostFormExists(key string) bool

func (*Request) Query added in v0.0.3

func (r *Request) Query(key string) string

func (*Request) QueryExists added in v0.0.3

func (r *Request) QueryExists(key string) bool

func (*Request) QueryOrDefault added in v0.0.20

func (r *Request) QueryOrDefault(key string, value string) string

func (*Request) SetBasicAuth added in v0.0.35

func (r *Request) SetBasicAuth(username string, password string)

func (*Request) SetContext added in v0.0.41

func (r *Request) SetContext(ctx context.Context)

func (*Request) SetHeader added in v0.0.3

func (r *Request) SetHeader(key string, value string)

type Response added in v0.0.3

type Response struct {
	Raw *http.Response
	// contains filtered or unexported fields
}

func WrapResponse

func WrapResponse(r *http.Response) *Response

func (*Response) Bytes added in v0.0.3

func (r *Response) Bytes() ([]byte, error)

func (*Response) Dump added in v0.0.36

func (r *Response) Dump(body bool) ([]byte, error)

func (*Response) JSON added in v0.0.36

func (r *Response) JSON(value interface{}) error

func (*Response) Pipe added in v0.0.60

func (r *Response) Pipe(writer io.Writer) error

func (*Response) SaveFile added in v0.0.60

func (r *Response) SaveFile(filename string) error

func (*Response) Stream added in v0.0.36

func (r *Response) Stream() (io.ReadCloser, error)

func (*Response) Text added in v0.0.3

func (r *Response) Text() (string, error)

func (*Response) XML added in v0.0.36

func (r *Response) XML(value interface{}) error

type ResponseWriter added in v0.0.3

type ResponseWriter interface {
	Raw() http.ResponseWriter
	StatusCode(statusCode int)
	Header(key string, value string) ResponseWriter
	Text(statusCode int, text string)
	HTML(statusCode int, content string)
	JSON(statusCode int, value interface{})
	XML(statusCode int, value interface{})
}

func WrapResponseWriter

func WrapResponseWriter(w http.ResponseWriter) ResponseWriter

type Router

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

func Default added in v0.0.60

func Default() *Router

func NewRouter added in v0.0.36

func NewRouter() *Router

func (*Router) Any

func (router *Router) Any(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router

func (*Router) Delete

func (router *Router) Delete(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router

func (*Router) Get

func (router *Router) Get(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router

func (*Router) Group

func (router *Router) Group(prefix string, middlewares ...Middleware) *group

func (*Router) Handle

func (router *Router) Handle(method string, path string, handler HandlerFunc, middlewares ...Middleware) *Router

func (*Router) HandleNotFound

func (router *Router) HandleNotFound(h HandlerFunc) *Router

func (*Router) Items added in v0.0.40

func (router *Router) Items() []EntryView

func (*Router) Options

func (router *Router) Options(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router

func (*Router) Patch

func (router *Router) Patch(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router

func (*Router) Post

func (router *Router) Post(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router

func (*Router) Prefix

func (router *Router) Prefix(p string) *Router

func (*Router) Put

func (router *Router) Put(pattern string, handler HandlerFunc, middlewares ...Middleware) *Router

func (*Router) Run

func (router *Router) Run(addr string) error

func (*Router) ServeHTTP

func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Router) String

func (router *Router) String() string

func (*Router) Use

func (router *Router) Use(middlewares ...Middleware) *Router

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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