README
¶
Middleware
Perhaps the wiki is the most up-to-date. https://github.com/poteto-go/poteto/wiki/Middleware
middleware list
name | summary |
---|---|
CORS | CORS Policy |
Camara | Some Security Header |
JWS | Secure JWT |
Timeout | Timeout |
RequestLogger | Log config on Request |
use middleware
package main
import (
"net/http"
"github.com/poteto-go/poteto"
"github.com/poteto-go/poteto/middleware"
)
func main() {
p := poteto.New()
p.Middleware(middleware.CORSWithConfig(CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete}}
))
// handler
...
}
Documentation
¶
Index ¶
- Variables
- func CORSWithConfig(config CORSConfig) poteto.MiddlewareFunc
- func CamaraWithConfig(config CamaraConfig) poteto.MiddlewareFunc
- func JWSWithConfig(cfg PotetoJWSConfig) poteto.MiddlewareFunc
- func RequestLoggerWithConfig(config RequestLoggerConfig) poteto.MiddlewareFunc
- func TimeoutWithConfig(config TimeoutConfig) poteto.MiddlewareFunc
- type CORSConfig
- type CamaraConfig
- type LogHandlerFunc
- type PotetoJWSConfig
- type RequestLoggerConfig
- type RequestLoggerValues
- type TimeoutConfig
- type TimeoutResponseEx
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultCORSConfig = CORSConfig{ AllowOrigins: []string{"*"}, AllowMethods: []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete}, }
View Source
var DefaultCamaraConfig = CamaraConfig{
ContentSecurityPolicy: "default-src 'self';base-uri 'self';block-all-mixed-content;font-src 'self' https: data:;frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests",
XFrameOption: "SAMEORIGIN",
StrictTransportSecurity: "max-age=15552000; includeSubDomains",
XDownloadOption: "noopen",
XContentTypeOption: "nosniff",
ReferrerPolicy: "no-referrer",
}
View Source
var DefaultJWSConfig = &potetoJWSConfig{ AuthScheme: constant.AUTH_SCHEME, SignMethod: constant.ALGORITHM_HS256, ContextKey: "user", ClaimsFunc: func(c poteto.Context) jwt.Claims { return jwt.MapClaims{} }, }
View Source
var DefaultRequestLoggerConfig = RequestLoggerConfig{ HasStatus: true, HasMethod: true, HasRoutePath: true, HasRequestID: true, HasUserAgent: true, HasRemoteIP: true, HasRealIP: true, HasHost: true, HasContentLength: true, OpenHeaders: []string{}, HasError: true, HasStartTime: true, HasEndTime: true, HasDuration: true, }
View Source
var DefaultTimeoutConfig = TimeoutConfig{ Limit: time.Second * 10, TimeoutResponse: DefaultTimeoutResponse, }
View Source
var DefaultTimeoutResponse = TimeoutResponseEx{
Message: "Gateway Time Out",
}
Functions ¶
func CORSWithConfig ¶
func CORSWithConfig(config CORSConfig) poteto.MiddlewareFunc
func CamaraWithConfig ¶
func CamaraWithConfig(config CamaraConfig) poteto.MiddlewareFunc
Provide Some Security Header
func JWSWithConfig ¶
func JWSWithConfig(cfg PotetoJWSConfig) poteto.MiddlewareFunc
func RequestLoggerWithConfig ¶
func RequestLoggerWithConfig(config RequestLoggerConfig) poteto.MiddlewareFunc
func TimeoutWithConfig ¶
func TimeoutWithConfig(config TimeoutConfig) poteto.MiddlewareFunc
Types ¶
type CORSConfig ¶
type CamaraConfig ¶
type CamaraConfig struct { ContentSecurityPolicy string `yaml:"content_security_policy"` XFrameOption string `yaml:"x_frame_option"` StrictTransportSecurity string `yaml:"strict_transport_security"` XDownloadOption string `yaml:"x_download_option"` XContentTypeOption string `yaml:"x_content_type_option"` ReferrerPolicy string `yaml:"referrer_policy"` }
type LogHandlerFunc ¶
type LogHandlerFunc func(ctx poteto.Context, rlv RequestLoggerValues) error
type PotetoJWSConfig ¶
type PotetoJWSConfig interface { KeyFunc(token *jwt.Token) (any, error) ParseToken(ctx poteto.Context, auth string) (any, error) }
func NewPotetoJWSConfig ¶
func NewPotetoJWSConfig(contextKey string, signKey any) PotetoJWSConfig
type RequestLoggerConfig ¶
type RequestLoggerConfig struct { HasStatus bool HasMethod bool HasRoutePath bool HasRequestID bool HasUserAgent bool HasRemoteIP bool HasRealIP bool HasHost bool HasContentLength bool OpenHeaders []string HasError bool HasStartTime bool HasEndTime bool HasDuration bool LogHandleFunc LogHandlerFunc }
type RequestLoggerValues ¶
type TimeoutConfig ¶
type TimeoutResponseEx ¶
type TimeoutResponseEx struct {
Message string `json:"message"`
}
Click to show internal directories.
Click to hide internal directories.