mirror of
				https://github.com/labstack/echo.git
				synced 2025-10-30 23:57:38 +02:00 
			
		
		
		
	| @@ -30,24 +30,24 @@ type ( | ||||
| 	} | ||||
| ) | ||||
|  | ||||
| // New returns an instance of `fasthttp.Server` with provided listen address. | ||||
| // New returns `fasthttp.Server` with provided listen address. | ||||
| func New(addr string) *Server { | ||||
| 	c := engine.Config{Address: addr} | ||||
| 	return NewFromConfig(c) | ||||
| 	return WithConfig(c) | ||||
| } | ||||
|  | ||||
| // NewFromTLS returns an instance of `fasthttp.Server` from TLS config. | ||||
| func NewFromTLS(addr, certfile, keyfile string) *Server { | ||||
| // WithTLS returns `fasthttp.Server` with TLS config. | ||||
| func WithTLS(addr, certfile, keyfile string) *Server { | ||||
| 	c := engine.Config{ | ||||
| 		Address:     addr, | ||||
| 		TLSCertfile: certfile, | ||||
| 		TLSKeyfile:  keyfile, | ||||
| 	} | ||||
| 	return NewFromConfig(c) | ||||
| 	return WithConfig(c) | ||||
| } | ||||
|  | ||||
| // NewFromConfig returns an instance of `standard.Server` from config. | ||||
| func NewFromConfig(c engine.Config) (s *Server) { | ||||
| // WithConfig returns `standard.Server` with config. | ||||
| func WithConfig(c engine.Config) (s *Server) { | ||||
| 	s = &Server{ | ||||
| 		Server: new(fasthttp.Server), | ||||
| 		config: c, | ||||
|   | ||||
| @@ -28,24 +28,24 @@ type ( | ||||
| 	} | ||||
| ) | ||||
|  | ||||
| // New returns an instance of `standard.Server` with provided listen address. | ||||
| // New returns `standard.Server` with provided listen address. | ||||
| func New(addr string) *Server { | ||||
| 	c := engine.Config{Address: addr} | ||||
| 	return NewFromConfig(c) | ||||
| 	return WithConfig(c) | ||||
| } | ||||
|  | ||||
| // NewFromTLS returns an instance of `standard.Server` from TLS config. | ||||
| func NewFromTLS(addr, certfile, keyfile string) *Server { | ||||
| // WithTLS returns `standard.Server` with TLS config. | ||||
| func WithTLS(addr, certfile, keyfile string) *Server { | ||||
| 	c := engine.Config{ | ||||
| 		Address:     addr, | ||||
| 		TLSCertfile: certfile, | ||||
| 		TLSKeyfile:  keyfile, | ||||
| 	} | ||||
| 	return NewFromConfig(c) | ||||
| 	return WithConfig(c) | ||||
| } | ||||
|  | ||||
| // NewFromConfig returns an instance of `standard.Server` from config. | ||||
| func NewFromConfig(c engine.Config) (s *Server) { | ||||
| // WithConfig returns `standard.Server` with config. | ||||
| func WithConfig(c engine.Config) (s *Server) { | ||||
| 	s = &Server{ | ||||
| 		Server: new(http.Server), | ||||
| 		config: c, | ||||
|   | ||||
| @@ -33,12 +33,12 @@ var ( | ||||
| func BasicAuth(f BasicAuthFunc) echo.MiddlewareFunc { | ||||
| 	c := DefaultBasicAuthConfig | ||||
| 	c.AuthFunc = f | ||||
| 	return BasicAuthFromConfig(c) | ||||
| 	return BasicAuthWithConfig(c) | ||||
| } | ||||
|  | ||||
| // BasicAuthFromConfig returns an HTTP basic auth middleware from config. | ||||
| // BasicAuthWithConfig returns an HTTP basic auth middleware from config. | ||||
| // See `BasicAuth()`. | ||||
| func BasicAuthFromConfig(config BasicAuthConfig) echo.MiddlewareFunc { | ||||
| func BasicAuthWithConfig(config BasicAuthConfig) echo.MiddlewareFunc { | ||||
| 	return func(next echo.HandlerFunc) echo.HandlerFunc { | ||||
| 		return func(c echo.Context) error { | ||||
| 			auth := c.Request().Header().Get(echo.HeaderAuthorization) | ||||
|   | ||||
| @@ -36,12 +36,12 @@ var ( | ||||
| // Gzip returns a middleware which compresses HTTP response using gzip compression | ||||
| // scheme. | ||||
| func Gzip() echo.MiddlewareFunc { | ||||
| 	return GzipFromConfig(DefaultGzipConfig) | ||||
| 	return GzipWithConfig(DefaultGzipConfig) | ||||
| } | ||||
|  | ||||
| // GzipFromConfig return gzip middleware from config. | ||||
| // GzipWithConfig return gzip middleware from config. | ||||
| // See `Gzip()`. | ||||
| func GzipFromConfig(config GzipConfig) echo.MiddlewareFunc { | ||||
| func GzipWithConfig(config GzipConfig) echo.MiddlewareFunc { | ||||
| 	// Defaults | ||||
| 	if config.Level == 0 { | ||||
| 		config.Level = DefaultGzipConfig.Level | ||||
|   | ||||
| @@ -55,12 +55,12 @@ var ( | ||||
| // CORS returns a Cross-Origin Resource Sharing (CORS) middleware. | ||||
| // See https://developer.mozilla.org/en/docs/Web/HTTP/Access_control_CORS | ||||
| func CORS() echo.MiddlewareFunc { | ||||
| 	return CORSFromConfig(DefaultCORSConfig) | ||||
| 	return CORSWithConfig(DefaultCORSConfig) | ||||
| } | ||||
|  | ||||
| // CORSFromConfig returns a CORS middleware from config. | ||||
| // CORSWithConfig returns a CORS middleware from config. | ||||
| // See `CORS()`. | ||||
| func CORSFromConfig(config CORSConfig) echo.MiddlewareFunc { | ||||
| func CORSWithConfig(config CORSConfig) echo.MiddlewareFunc { | ||||
| 	// Defaults | ||||
| 	if len(config.AllowOrigins) == 0 { | ||||
| 		config.AllowOrigins = DefaultCORSConfig.AllowOrigins | ||||
|   | ||||
| @@ -14,7 +14,7 @@ func TestCORS(t *testing.T) { | ||||
| 	rq := test.NewRequest(echo.GET, "/", nil) | ||||
| 	rc := test.NewResponseRecorder() | ||||
| 	c := echo.NewContext(rq, rc, e) | ||||
| 	cors := CORSFromConfig(CORSConfig{ | ||||
| 	cors := CORSWithConfig(CORSConfig{ | ||||
| 		AllowCredentials: true, | ||||
| 	}) | ||||
| 	h := cors(func(c echo.Context) error { | ||||
| @@ -38,7 +38,7 @@ func TestCORS(t *testing.T) { | ||||
| 	rc = test.NewResponseRecorder() | ||||
| 	c = echo.NewContext(rq, rc, e) | ||||
| 	rq.Header().Set(echo.HeaderOrigin, "localhost") | ||||
| 	cors = CORSFromConfig(CORSConfig{ | ||||
| 	cors = CORSWithConfig(CORSConfig{ | ||||
| 		AllowOrigins:     []string{"localhost"}, | ||||
| 		AllowCredentials: true, | ||||
| 		MaxAge:           3600, | ||||
|   | ||||
| @@ -54,12 +54,12 @@ var ( | ||||
|  | ||||
| // Logger returns a middleware that logs HTTP requests. | ||||
| func Logger() echo.MiddlewareFunc { | ||||
| 	return LoggerFromConfig(DefaultLoggerConfig) | ||||
| 	return LoggerWithConfig(DefaultLoggerConfig) | ||||
| } | ||||
|  | ||||
| // LoggerFromConfig returns a logger middleware from config. | ||||
| // LoggerWithConfig returns a logger middleware from config. | ||||
| // See `Logger()`. | ||||
| func LoggerFromConfig(config LoggerConfig) echo.MiddlewareFunc { | ||||
| func LoggerWithConfig(config LoggerConfig) echo.MiddlewareFunc { | ||||
| 	// Defaults | ||||
| 	if config.Format == "" { | ||||
| 		config.Format = DefaultLoggerConfig.Format | ||||
|   | ||||
| @@ -38,12 +38,12 @@ var ( | ||||
| // Recover returns a middleware which recovers from panics anywhere in the chain | ||||
| // and handles the control to the centralized HTTPErrorHandler. | ||||
| func Recover() echo.MiddlewareFunc { | ||||
| 	return RecoverFromConfig(DefaultRecoverConfig) | ||||
| 	return RecoverWithConfig(DefaultRecoverConfig) | ||||
| } | ||||
|  | ||||
| // RecoverFromConfig returns a recover middleware from config. | ||||
| // RecoverWithConfig returns a recover middleware from config. | ||||
| // See `Recover()`. | ||||
| func RecoverFromConfig(config RecoverConfig) echo.MiddlewareFunc { | ||||
| func RecoverWithConfig(config RecoverConfig) echo.MiddlewareFunc { | ||||
| 	// Defaults | ||||
| 	if config.StackSize == 0 { | ||||
| 		config.StackSize = DefaultRecoverConfig.StackSize | ||||
|   | ||||
| @@ -12,7 +12,7 @@ type ( | ||||
| 	// StaticConfig defines the config for static middleware. | ||||
| 	StaticConfig struct { | ||||
| 		// Root is the directory from where the static content is served. | ||||
| 		// Optional with default value as "". | ||||
| 		// Required. | ||||
| 		Root string `json:"root"` | ||||
|  | ||||
| 		// Index is the list of index files to be searched and used when serving | ||||
| @@ -40,12 +40,12 @@ var ( | ||||
| func Static(root string) echo.MiddlewareFunc { | ||||
| 	c := DefaultStaticConfig | ||||
| 	c.Root = root | ||||
| 	return StaticFromConfig(c) | ||||
| 	return StaticWithConfig(c) | ||||
| } | ||||
|  | ||||
| // StaticFromConfig returns a static middleware from config. | ||||
| // StaticWithConfig returns a static middleware from config. | ||||
| // See `Static()`. | ||||
| func StaticFromConfig(config StaticConfig) echo.MiddlewareFunc { | ||||
| func StaticWithConfig(config StaticConfig) echo.MiddlewareFunc { | ||||
| 	// Defaults | ||||
| 	if config.Index == nil { | ||||
| 		config.Index = DefaultStaticConfig.Index | ||||
|   | ||||
		Reference in New Issue
	
	Block a user