From 1a7bc677da28c85aaada4ef2013b3b11695c8e18 Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Thu, 7 Apr 2016 21:20:50 -0700 Subject: [PATCH] API changes from to with Signed-off-by: Vishal Rana --- engine/fasthttp/server.go | 14 +++++++------- engine/standard/server.go | 14 +++++++------- middleware/auth.go | 6 +++--- middleware/compress.go | 6 +++--- middleware/cors.go | 6 +++--- middleware/cors_test.go | 4 ++-- middleware/logger.go | 6 +++--- middleware/recover.go | 6 +++--- middleware/static.go | 8 ++++---- 9 files changed, 35 insertions(+), 35 deletions(-) diff --git a/engine/fasthttp/server.go b/engine/fasthttp/server.go index 7645f089..1826a053 100644 --- a/engine/fasthttp/server.go +++ b/engine/fasthttp/server.go @@ -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, diff --git a/engine/standard/server.go b/engine/standard/server.go index 93ada8ea..96d6bbb5 100644 --- a/engine/standard/server.go +++ b/engine/standard/server.go @@ -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, diff --git a/middleware/auth.go b/middleware/auth.go index 93eeda7b..8800b16e 100644 --- a/middleware/auth.go +++ b/middleware/auth.go @@ -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) diff --git a/middleware/compress.go b/middleware/compress.go index 1f113e45..b3f7fad0 100644 --- a/middleware/compress.go +++ b/middleware/compress.go @@ -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 diff --git a/middleware/cors.go b/middleware/cors.go index dc18a024..9cb6ff08 100644 --- a/middleware/cors.go +++ b/middleware/cors.go @@ -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 diff --git a/middleware/cors_test.go b/middleware/cors_test.go index 7b2d24e8..89351488 100644 --- a/middleware/cors_test.go +++ b/middleware/cors_test.go @@ -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, diff --git a/middleware/logger.go b/middleware/logger.go index c150e692..fa83a0b2 100644 --- a/middleware/logger.go +++ b/middleware/logger.go @@ -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 diff --git a/middleware/recover.go b/middleware/recover.go index cb3bf2dc..c437ceee 100644 --- a/middleware/recover.go +++ b/middleware/recover.go @@ -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 diff --git a/middleware/static.go b/middleware/static.go index 2e839533..ec210f8c 100644 --- a/middleware/static.go +++ b/middleware/static.go @@ -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