Documentation ¶
Index ¶
- Constants
- Variables
- func FromHeader(schema string) func(r *http.Request) (string, error)
- func FromRequestID(ctx context.Context) string
- func NameOfFunction(f interface{}) string
- func NewHandlerWrap(h interface{}) http.Handler
- func RequestIDTransport(c context.Context, tr http.RoundTripper) http.RoundTripper
- type AuthOption
- type Builder
- type Cache
- type Choice
- type Choices
- type Context
- type DefaultResponseBody
- type HandlerFunc
- func Auth(opt AuthOption) HandlerFunc
- func Logger() HandlerFunc
- func LoggerWithConfig(config LoggerConfig) HandlerFunc
- func Permission(permissionClaim string, permissions ...string) HandlerFunc
- func Proxy(balancer ProxyBalancer) HandlerFunc
- func ProxyWithConfig(config ProxyConfig) HandlerFunc
- func Recovery() HandlerFunc
- func RequestID() HandlerFunc
- func RequestIDWithConfig(config RequestIDConfig) HandlerFunc
- func WrapHandler(h http.Handler) HandlerFunc
- type HandlerFuncChain
- type HandlerMiddleware
- type HandlerWrap
- type ILogger
- type KeyFunc
- type LogFormatType
- type LogLevel
- type LogTemplate
- type LoggerConfig
- type MapRouterInformations
- type Options
- type Param
- type Params
- type ProxyBalancer
- type ProxyConfig
- type ProxyTarget
- type Random
- type RequestIDConfig
- type ResponseWriter
- type Router
- func (r *Router) Any(path string, h ...HandlerFunc) *Router
- func (r *Router) DELETE(path string, h ...HandlerFunc)
- func (r *Router) GET(path string, h ...HandlerFunc)
- func (r *Router) Group(path string, middleware ...HandlerFunc) *Router
- func (r *Router) HEAD(path string, h ...HandlerFunc)
- func (r *Router) Handler(method, path string, h ...HandlerFunc)
- func (r *Router) NoMethod(h ...HandlerFunc) *Router
- func (r *Router) NotFound(h ...HandlerFunc) *Router
- func (r *Router) OPTIONS(path string, h ...HandlerFunc)
- func (r *Router) PATCH(path string, h ...HandlerFunc)
- func (r *Router) POST(path string, h ...HandlerFunc)
- func (r *Router) PUT(path string, h ...HandlerFunc)
- func (r *Router) Run(port int) error
- func (r *Router) RunTLS(port int, certFile, keyFile string) error
- func (r *Router) RunUnix(file string) error
- func (r *Router) ServeFiles(paths string, fs http.FileSystem)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) Use(middleware ...HandlerFunc)
- type RouterInfo
- type TokenExtractorFunc
- type WeightProxyTarget
Constants ¶
View Source
const ( Uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" Lowercase = "abcdefghijklmnopqrstuvwxyz" Alphabetic = Uppercase + Lowercase Numeric = "0123456789" Alphanumeric = Alphabetic + Numeric )
View Source
const (
AuthKey = "auth_key"
)
View Source
const FormatTemplate = "time:${time_millisec}\tid:${id}\tremote_ip:${remote_ip}\thost:${host}\tmethod:${method}\turi:${uri}\tuser_agent:${user_agent}\t" +
"status:${status}\terror:${error}\tlatency:${latency}\tlatency_human:${latency_human}\tbytes_in:${bytes_in}\tbytes_out:${bytes_out}"
View Source
const StatusCodeContextCanceled = 499
Variables ¶
View Source
var ( ErrEmptyAuthorization = errors.New("token_required") ErrInvalidTokenRequest = errors.New("invalid_request") ErrInvalidToken = errors.New("invalid_token") )
View Source
var ( Version = "" Revision = "" )
View Source
var DefaultLogger = NewLogger(os.Stderr, FormatShort, FormatDatetime)
View Source
var DefaultLoggerConfig = LoggerConfig{ Format: FormatTemplate, CustomTimeFormat: FormatMillisec.String(), }
View Source
var MinMaxError = errors.New("Min cannot be greater than max.")
Functions ¶
func FromHeader ¶ added in v0.0.2
func FromRequestID ¶ added in v0.0.2
func NameOfFunction ¶ added in v0.0.2
func NameOfFunction(f interface{}) string
func NewHandlerWrap ¶
func RequestIDTransport ¶ added in v0.0.2
func RequestIDTransport(c context.Context, tr http.RoundTripper) http.RoundTripper
Types ¶
type AuthOption ¶ added in v0.0.2
type Context ¶
type Context interface { Writer() ResponseWriter SetWriter(w ResponseWriter) GetStatus() int SetStatus(status int) ResponseSize() int SetHeader(key, value string) /* Request */ Request() *http.Request SetRequest(r *http.Request) Header() http.Header GetContext() context.Context SetContext(ctx context.Context) IsWebSocket() bool Scheme() string /* Abort or error */ AbortWithStatus(status int) AbortWithStatusAndErrorMessage(status int, err error) AbortWithStatusAndMessage(status int, v interface{}) Error(err error) GetError() []error // Skip is 後続の処理を止める IsSkip() bool Skip() /* Query or URL parameter */ Param(name string) string Params() Params QueryParam(name string) string DefaultQuery(name string, defaultValue string) string /* Request body */ ReadJsonBody(v interface{}) error FormValue(name string) string FormFile(name string) (*multipart.FileHeader, error) MultiPartForm() (*multipart.Form, error) /* Cookie */ SetCookie(cookie *http.Cookie) Cookie(name string) (*http.Cookie, error) Cookies() []*http.Cookie /* Response body */ Render(status int, r render.Render) String(status int, format string, v ...interface{}) JSON(status int, v interface{}) JSONP(status int, v interface{}) IndentJSON(status int, v interface{}, indent string) AsciiJSON(status int, v interface{}) YAML(status int, v interface{}) Template(status int, v interface{}, filenames ...string) TemplateText(status int, text string, v interface{}) /* Middlewere or handler */ Next() HandlerName() string Logger() ILogger ClientIP() string Set(key string, value interface{}) Get(key string) interface{} Redirect(status int, url string) GetRequestID() string /* Utils */ // HttpClient when the tr is nil, the default transport is http.DefaultTransport HttpClient(tr http.RoundTripper) *http.Client Path() string RealPath() string Method() string RealMethod() string }
type DefaultResponseBody ¶
type DefaultResponseBody struct { Code int `json:"code"` Status string `json:"status"` Message string `json:"message"` Internal error `json:"-"` }
func NewDefaultResponseBody ¶
func NewDefaultResponseBody(code int, message string) *DefaultResponseBody
func (*DefaultResponseBody) Error ¶ added in v0.0.2
func (d *DefaultResponseBody) Error() string
type HandlerFunc ¶
type HandlerFunc func(Context)
func Auth ¶ added in v0.0.2
func Auth(opt AuthOption) HandlerFunc
func Logger ¶
func Logger() HandlerFunc
func LoggerWithConfig ¶ added in v0.0.2
func LoggerWithConfig(config LoggerConfig) HandlerFunc
func Permission ¶ added in v0.0.2
func Permission(permissionClaim string, permissions ...string) HandlerFunc
func Proxy ¶ added in v0.0.2
func Proxy(balancer ProxyBalancer) HandlerFunc
func ProxyWithConfig ¶ added in v0.0.2
func ProxyWithConfig(config ProxyConfig) HandlerFunc
func Recovery ¶
func Recovery() HandlerFunc
func RequestID ¶ added in v0.0.2
func RequestID() HandlerFunc
func RequestIDWithConfig ¶ added in v0.0.2
func RequestIDWithConfig(config RequestIDConfig) HandlerFunc
func WrapHandler ¶
func WrapHandler(h http.Handler) HandlerFunc
type HandlerFuncChain ¶ added in v0.0.2
type HandlerFuncChain []HandlerFunc
func (HandlerFuncChain) Last ¶ added in v0.0.2
func (hc HandlerFuncChain) Last() HandlerFunc
func (HandlerFuncChain) LastIndex ¶ added in v0.0.2
func (hc HandlerFuncChain) LastIndex() int
type HandlerWrap ¶
type HandlerWrap struct {
// contains filtered or unexported fields
}
func (*HandlerWrap) ServeHTTP ¶
func (h *HandlerWrap) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ILogger ¶
type ILogger interface { Debug(v ...interface{}) Info(v ...interface{}) Warning(v ...interface{}) Error(v ...interface{}) Critical(v ...interface{}) Write(b []byte) (int, error) // Copy is logger copy instance Copy() ILogger // Skip is logger skip plus instance Skip(n int) ILogger ChangeFormatType(formatType LogFormatType) ILogger }
var Log ILogger = &logger{}
func NewLogger ¶
func NewLogger(writer io.Writer, formatType LogFormatType, timeFmtTyp LogFormatType) ILogger
type LogFormatType ¶
type LogFormatType string
const ( // FormatShort time:{{.Time}}\tlevel:{{.Level}}\tmessage:{{.Message}}\n FormatShort LogFormatType = "time:{{.Time}}\tlevel:{{.Level}}\tmessage:{{.Message}}\n" // FormatStandard time:{{.Time}}\tlevel:{{.Level}}\tfilename:{{.Filename}}:{{.LineNumber}}\tmessage:{{.Message}}\n FormatStandard LogFormatType = "time:{{.Time}}\tlevel:{{.Level}}\tfilename:{{.Filename}}:{{.LineNumber}}\tmessage:{{.Message}}\n" // FormatLong time:{{.Time}}\tlevel:{{.Level}}\tfilename:{{.Filename}}:{{.LineNumber}}\tfuncname:{{.Funcname}}\tmessage:{{.Message}}\n FormatLong LogFormatType = "time:{{.Time}}\tlevel:{{.Level}}\tfilename:{{.Filename}}:{{.LineNumber}}\tfuncname:{{.Funcname}}\tmessage:{{.Message}}\n" // FormatDate 2006/01/02 FormatDate LogFormatType = "2006/01/02" // FormatDatetime 2006/01/02 15:04:05 FormatDatetime LogFormatType = "2006/01/02 15:04:05" // FormatMillisec 2006/01/02 15:04:05.00000 FormatMillisec LogFormatType = "2006/01/02 15:04:05.00000" )
func ConvertLogFmt ¶
func ConvertLogFmt(fmt string) LogFormatType
func ConvertTimeFmt ¶
func ConvertTimeFmt(fmt string) LogFormatType
func (LogFormatType) String ¶
func (f LogFormatType) String() string
type LogTemplate ¶
type LoggerConfig ¶ added in v0.0.2
type MapRouterInformations ¶ added in v0.0.5
type MapRouterInformations map[string][]RouterInfo
type Params ¶ added in v0.0.6
type Params []Param
Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.
func (Params) ByName ¶ added in v0.0.6
ByName returns the value of the first Param which key matches the given name. If no matching Param is found, an empty string is returned.
type ProxyBalancer ¶ added in v0.0.2
type ProxyBalancer interface { Add(target interface{}) bool Remove(name string) bool Next(c Context) *ProxyTarget }
func NewRandomBalancer ¶ added in v0.0.2
func NewRandomBalancer(proxies []*ProxyTarget) ProxyBalancer
func NewRoundRobinBalancer ¶ added in v0.0.2
func NewRoundRobinBalancer(proxies []*ProxyTarget) ProxyBalancer
func NewStaticWeightedRoundRobinBalancer ¶ added in v0.0.3
func NewStaticWeightedRoundRobinBalancer(proxies []*WeightProxyTarget) ProxyBalancer
type ProxyConfig ¶ added in v0.0.2
type ProxyTarget ¶ added in v0.0.2
type RequestIDConfig ¶ added in v0.0.2
type RequestIDConfig struct {
Generator func() string
}
type ResponseWriter ¶ added in v0.0.2
type Router ¶ added in v0.0.2
type Router struct { UseRawPath bool UnescapePathValues bool RemoveExtraSlash bool RedirectFixedPath bool HandleMethodNotAllowed bool // contains filtered or unexported fields }
func (*Router) DELETE ¶ added in v0.0.2
func (r *Router) DELETE(path string, h ...HandlerFunc)
func (*Router) GET ¶ added in v0.0.2
func (r *Router) GET(path string, h ...HandlerFunc)
func (*Router) Group ¶ added in v0.0.2
func (r *Router) Group(path string, middleware ...HandlerFunc) *Router
func (*Router) HEAD ¶ added in v0.0.2
func (r *Router) HEAD(path string, h ...HandlerFunc)
func (*Router) Handler ¶ added in v0.0.2
func (r *Router) Handler(method, path string, h ...HandlerFunc)
func (*Router) NoMethod ¶ added in v0.0.6
func (r *Router) NoMethod(h ...HandlerFunc) *Router
func (*Router) NotFound ¶ added in v0.0.6
func (r *Router) NotFound(h ...HandlerFunc) *Router
func (*Router) OPTIONS ¶ added in v0.0.2
func (r *Router) OPTIONS(path string, h ...HandlerFunc)
func (*Router) PATCH ¶ added in v0.0.2
func (r *Router) PATCH(path string, h ...HandlerFunc)
func (*Router) POST ¶ added in v0.0.2
func (r *Router) POST(path string, h ...HandlerFunc)
func (*Router) PUT ¶ added in v0.0.2
func (r *Router) PUT(path string, h ...HandlerFunc)
func (*Router) RunUnix ¶ added in v0.0.2
RunUnix is unix domain socket
When the file is empty, the default name is www.sock
func (*Router) ServeFiles ¶ added in v0.0.2
func (r *Router) ServeFiles(paths string, fs http.FileSystem)
func (*Router) ServeHTTP ¶ added in v0.0.2
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (*Router) Use ¶ added in v0.0.2
func (r *Router) Use(middleware ...HandlerFunc)
type RouterInfo ¶ added in v0.0.5
type TokenExtractorFunc ¶ added in v0.0.2
func FromParameter ¶ added in v0.0.2
func FromParameter(parameterName string) TokenExtractorFunc
type WeightProxyTarget ¶ added in v0.0.3
type WeightProxyTarget struct { Weight float64 *ProxyTarget }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.