mirror of
https://github.com/labstack/echo.git
synced 2025-07-05 00:58:47 +02:00
10
README.md
10
README.md
@ -28,11 +28,11 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
## [Get Started](https://echo.labstack.com/guide)
|
## [Guide](https://echo.labstack.com/guide)
|
||||||
|
|
||||||
### Example:
|
## Example
|
||||||
|
|
||||||
```
|
```go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -45,11 +45,14 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
// Echo instance
|
// Echo instance
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
e.Use(middleware.Logger())
|
e.Use(middleware.Logger())
|
||||||
e.Use(middleware.Recover())
|
e.Use(middleware.Recover())
|
||||||
|
|
||||||
// Routes
|
// Routes
|
||||||
e.GET("/", hello)
|
e.GET("/", hello)
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
e.Logger.Fatal(e.Start(":1323"))
|
e.Logger.Fatal(e.Start(":1323"))
|
||||||
}
|
}
|
||||||
@ -58,7 +61,6 @@ func main() {
|
|||||||
func hello(c echo.Context) error {
|
func hello(c echo.Context) error {
|
||||||
return c.String(http.StatusOK, "Hello, World!")
|
return c.String(http.StatusOK, "Hello, World!")
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Support Us
|
## Support Us
|
||||||
|
@ -88,6 +88,7 @@ func BasicAuthWithConfig(config BasicAuthConfig) echo.MiddlewareFunc {
|
|||||||
} else if valid {
|
} else if valid {
|
||||||
return next(c)
|
return next(c)
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,8 @@ func HTTPSRedirect() echo.MiddlewareFunc {
|
|||||||
// HTTPSRedirectWithConfig returns an HTTPSRedirect middleware with config.
|
// HTTPSRedirectWithConfig returns an HTTPSRedirect middleware with config.
|
||||||
// See `HTTPSRedirect()`.
|
// See `HTTPSRedirect()`.
|
||||||
func HTTPSRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc {
|
func HTTPSRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc {
|
||||||
return redirect(config, func(isTLS bool, _, host, uri string) (ok bool, url string) {
|
return redirect(config, func(tls bool, _, host, uri string) (ok bool, url string) {
|
||||||
if ok = !isTLS; ok {
|
if ok = !tls; ok {
|
||||||
url = "https://" + host + uri
|
url = "https://" + host + uri
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -59,8 +59,8 @@ func HTTPSWWWRedirect() echo.MiddlewareFunc {
|
|||||||
// HTTPSWWWRedirectWithConfig returns an HTTPSRedirect middleware with config.
|
// HTTPSWWWRedirectWithConfig returns an HTTPSRedirect middleware with config.
|
||||||
// See `HTTPSWWWRedirect()`.
|
// See `HTTPSWWWRedirect()`.
|
||||||
func HTTPSWWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc {
|
func HTTPSWWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc {
|
||||||
return redirect(config, func(isTLS bool, _, host, uri string) (ok bool, url string) {
|
return redirect(config, func(tls bool, _, host, uri string) (ok bool, url string) {
|
||||||
if ok = !isTLS && host[:3] != www; ok {
|
if ok = !tls && host[:3] != www; ok {
|
||||||
url = "https://www." + host + uri
|
url = "https://www." + host + uri
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -78,8 +78,8 @@ func HTTPSNonWWWRedirect() echo.MiddlewareFunc {
|
|||||||
// HTTPSNonWWWRedirectWithConfig returns an HTTPSRedirect middleware with config.
|
// HTTPSNonWWWRedirectWithConfig returns an HTTPSRedirect middleware with config.
|
||||||
// See `HTTPSNonWWWRedirect()`.
|
// See `HTTPSNonWWWRedirect()`.
|
||||||
func HTTPSNonWWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc {
|
func HTTPSNonWWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc {
|
||||||
return redirect(config, func(isTLS bool, _, host, uri string) (ok bool, url string) {
|
return redirect(config, func(tls bool, _, host, uri string) (ok bool, url string) {
|
||||||
if ok = !isTLS; ok {
|
if ok = !tls; ok {
|
||||||
if host[:3] == www {
|
if host[:3] == www {
|
||||||
host = host[4:]
|
host = host[4:]
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ func NonWWWRedirect() echo.MiddlewareFunc {
|
|||||||
// NonWWWRedirectWithConfig returns an HTTPSRedirect middleware with config.
|
// NonWWWRedirectWithConfig returns an HTTPSRedirect middleware with config.
|
||||||
// See `NonWWWRedirect()`.
|
// See `NonWWWRedirect()`.
|
||||||
func NonWWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc {
|
func NonWWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc {
|
||||||
return redirect(config, func(isTLS bool, scheme, host, uri string) (ok bool, url string) {
|
return redirect(config, func(tls bool, scheme, host, uri string) (ok bool, url string) {
|
||||||
if ok = host[:3] == www; ok {
|
if ok = host[:3] == www; ok {
|
||||||
url = scheme + "://" + host[4:] + uri
|
url = scheme + "://" + host[4:] + uri
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user