mirror of
https://github.com/labstack/echo.git
synced 2024-11-24 08:22:21 +02:00
Updated docs
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
948d607539
commit
6bb7747530
8
group.go
8
group.go
@ -1,8 +1,12 @@
|
|||||||
package echo
|
package echo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path"
|
||||||
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Group is a set of sub-routes for a specified route. It can be used for inner
|
// Group is a set of sub-routes for a specified route. It can be used for inner
|
||||||
// routes that share a common middlware or functionality that should be separate
|
// routes that share a common middleware or functionality that should be separate
|
||||||
// from the parent echo instance while still inheriting from it.
|
// from the parent echo instance while still inheriting from it.
|
||||||
Group struct {
|
Group struct {
|
||||||
prefix string
|
prefix string
|
||||||
@ -16,7 +20,7 @@ func (g *Group) Use(middleware ...MiddlewareFunc) {
|
|||||||
g.middleware = append(g.middleware, middleware...)
|
g.middleware = append(g.middleware, middleware...)
|
||||||
// Allow all requests to reach the group as they might get dropped if router
|
// Allow all requests to reach the group as they might get dropped if router
|
||||||
// doesn't find a match, making none of the group middleware process.
|
// doesn't find a match, making none of the group middleware process.
|
||||||
g.echo.Any(g.prefix+"/*", func(c Context) error {
|
g.echo.Any(path.Clean(g.prefix+"/*"), func(c Context) error {
|
||||||
return ErrNotFound
|
return ErrNotFound
|
||||||
}, g.middleware...)
|
}, g.middleware...)
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ description = "Serving static files in Echo"
|
|||||||
|
|
||||||
Images, JavaScript, CSS, PDF, Fonts and so on...
|
Images, JavaScript, CSS, PDF, Fonts and so on...
|
||||||
|
|
||||||
|
## [Using Static Middleware]({{< ref "middleware/static.md">}})
|
||||||
|
|
||||||
## Using `Echo#Static()`
|
## Using `Echo#Static()`
|
||||||
|
|
||||||
`Echo#Static(prefix, root string)` registers a new route with path prefix to serve
|
`Echo#Static(prefix, root string)` registers a new route with path prefix to serve
|
||||||
|
@ -52,6 +52,6 @@ BasicAuthConfig struct {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
DefaultBasicAuthConfig = BasicAuthConfig{
|
DefaultBasicAuthConfig = BasicAuthConfig{
|
||||||
Skipper: defaultSkipper,
|
Skipper: DefaultSkipper,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -48,6 +48,6 @@ BodyLimitConfig struct {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
DefaultBodyLimitConfig = BodyLimitConfig{
|
DefaultBodyLimitConfig = BodyLimitConfig{
|
||||||
Skipper: defaultSkipper,
|
Skipper: DefaultSkipper,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -72,7 +72,7 @@ CORSConfig struct {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
DefaultCORSConfig = CORSConfig{
|
DefaultCORSConfig = CORSConfig{
|
||||||
Skipper: defaultSkipper,
|
Skipper: DefaultSkipper,
|
||||||
AllowOrigins: []string{"*"},
|
AllowOrigins: []string{"*"},
|
||||||
AllowMethods: []string{echo.GET, echo.HEAD, echo.PUT, echo.PATCH, echo.POST, echo.DELETE},
|
AllowMethods: []string{echo.GET, echo.HEAD, echo.PUT, echo.PATCH, echo.POST, echo.DELETE},
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ CSRFConfig struct {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
DefaultCSRFConfig = CSRFConfig{
|
DefaultCSRFConfig = CSRFConfig{
|
||||||
Skipper: defaultSkipper,
|
Skipper: DefaultSkipper,
|
||||||
TokenLength: 32,
|
TokenLength: 32,
|
||||||
TokenLookup: "header:" + echo.HeaderXCSRFToken,
|
TokenLookup: "header:" + echo.HeaderXCSRFToken,
|
||||||
ContextKey: "csrf",
|
ContextKey: "csrf",
|
||||||
|
@ -41,7 +41,7 @@ GzipConfig struct {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
DefaultGzipConfig = GzipConfig{
|
DefaultGzipConfig = GzipConfig{
|
||||||
Skipper: defaultSkipper,
|
Skipper: DefaultSkipper,
|
||||||
Level: -1,
|
Level: -1,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -71,7 +71,7 @@ JWTConfig struct {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
DefaultJWTConfig = JWTConfig{
|
DefaultJWTConfig = JWTConfig{
|
||||||
Skipper: defaultSkipper,
|
Skipper: DefaultSkipper,
|
||||||
SigningMethod: AlgorithmHS256,
|
SigningMethod: AlgorithmHS256,
|
||||||
ContextKey: "user",
|
ContextKey: "user",
|
||||||
TokenLookup: "header:" + echo.HeaderAuthorization,
|
TokenLookup: "header:" + echo.HeaderAuthorization,
|
||||||
|
@ -62,7 +62,7 @@ KeyAuthConfig struct {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
DefaultKeyAuthConfig = KeyAuthConfig{
|
DefaultKeyAuthConfig = KeyAuthConfig{
|
||||||
Skipper: defaultSkipper,
|
Skipper: DefaultSkipper,
|
||||||
KeyLookup: "header:" + echo.HeaderAuthorization,
|
KeyLookup: "header:" + echo.HeaderAuthorization,
|
||||||
AuthScheme: "Bearer",
|
AuthScheme: "Bearer",
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ LoggerConfig struct {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
DefaultLoggerConfig = LoggerConfig{
|
DefaultLoggerConfig = LoggerConfig{
|
||||||
Skipper: defaultSkipper,
|
Skipper: DefaultSkipper,
|
||||||
Format: `{"time":"${time_rfc3339_nano}","remote_ip":"${remote_ip}","host":"${host}",` +
|
Format: `{"time":"${time_rfc3339_nano}","remote_ip":"${remote_ip}","host":"${host}",` +
|
||||||
`"method":"${method}","uri":"${uri}","status":${status}, "latency":${latency},` +
|
`"method":"${method}","uri":"${uri}","status":${status}, "latency":${latency},` +
|
||||||
`"latency_human":"${latency_human}","bytes_in":${bytes_in},` +
|
`"latency_human":"${latency_human}","bytes_in":${bytes_in},` +
|
||||||
|
@ -44,7 +44,7 @@ MethodOverrideConfig struct {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
DefaultMethodOverrideConfig = MethodOverrideConfig{
|
DefaultMethodOverrideConfig = MethodOverrideConfig{
|
||||||
Skipper: defaultSkipper,
|
Skipper: DefaultSkipper,
|
||||||
Getter: MethodFromHeader(echo.HeaderXHTTPMethodOverride),
|
Getter: MethodFromHeader(echo.HeaderXHTTPMethodOverride),
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -55,7 +55,7 @@ RecoverConfig struct {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
DefaultRecoverConfig = RecoverConfig{
|
DefaultRecoverConfig = RecoverConfig{
|
||||||
Skipper: defaultSkipper,
|
Skipper: DefaultSkipper,
|
||||||
StackSize: 4 << 10, // 4 KB
|
StackSize: 4 << 10, // 4 KB
|
||||||
DisableStackAll: false,
|
DisableStackAll: false,
|
||||||
DisablePrintStack: false,
|
DisablePrintStack: false,
|
||||||
|
@ -98,7 +98,7 @@ RedirectConfig struct {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
DefaultRedirectConfig = RedirectConfig{
|
DefaultRedirectConfig = RedirectConfig{
|
||||||
Skipper: defaultSkipper,
|
Skipper: DefaultSkipper,
|
||||||
Code: http.StatusMovedPermanently,
|
Code: http.StatusMovedPermanently,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -88,7 +88,7 @@ SecureConfig struct {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
DefaultSecureConfig = SecureConfig{
|
DefaultSecureConfig = SecureConfig{
|
||||||
Skipper: defaultSkipper,
|
Skipper: DefaultSkipper,
|
||||||
XSSProtection: "1; mode=block",
|
XSSProtection: "1; mode=block",
|
||||||
ContentTypeNosniff: "nosniff",
|
ContentTypeNosniff: "nosniff",
|
||||||
XFrameOptions: "SAMEORIGIN",
|
XFrameOptions: "SAMEORIGIN",
|
||||||
|
69
website/content/middleware/static.md
Normal file
69
website/content/middleware/static.md
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
+++
|
||||||
|
title = "Static Middleware"
|
||||||
|
description = "Static middleware for Echo"
|
||||||
|
[menu.main]
|
||||||
|
name = "Static"
|
||||||
|
parent = "middleware"
|
||||||
|
weight = 5
|
||||||
|
+++
|
||||||
|
|
||||||
|
Static middleware can be used to serve static files from the provided root directory.
|
||||||
|
|
||||||
|
*Usage*
|
||||||
|
|
||||||
|
```go
|
||||||
|
e := echo.New()
|
||||||
|
e.Use(middleware.Static("/static"))
|
||||||
|
```
|
||||||
|
|
||||||
|
This serves static files from `static` directory. For example, a request to `/js/main.js`
|
||||||
|
will fetch and serve `static/js/main.js` file.
|
||||||
|
|
||||||
|
## Custom Configuration
|
||||||
|
|
||||||
|
*Usage*
|
||||||
|
|
||||||
|
```go
|
||||||
|
e := echo.New()
|
||||||
|
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
||||||
|
Root: "static",
|
||||||
|
Browse: true,
|
||||||
|
}))
|
||||||
|
```
|
||||||
|
|
||||||
|
This serves static files from `static` directory and enables directory browsing.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
```go
|
||||||
|
StaticConfig struct {
|
||||||
|
// Skipper defines a function to skip middleware.
|
||||||
|
Skipper Skipper
|
||||||
|
|
||||||
|
// Root directory from where the static content is served.
|
||||||
|
// Required.
|
||||||
|
Root string `json:"root"`
|
||||||
|
|
||||||
|
// Index file for serving a directory.
|
||||||
|
// Optional. Default value "index.html".
|
||||||
|
Index string `json:"index"`
|
||||||
|
|
||||||
|
// Enable HTML5 mode by forwarding all not-found requests to root so that
|
||||||
|
// SPA (single-page application) can handle the routing.
|
||||||
|
// Optional. Default value false.
|
||||||
|
HTML5 bool `json:"html5"`
|
||||||
|
|
||||||
|
// Enable directory browsing.
|
||||||
|
// Optional. Default value false.
|
||||||
|
Browse bool `json:"browse"`
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
*Default Configuration*
|
||||||
|
|
||||||
|
```go
|
||||||
|
DefaultStaticConfig = StaticConfig{
|
||||||
|
Skipper: DefaultSkipper,
|
||||||
|
Index: "index.html",
|
||||||
|
}
|
||||||
|
```
|
@ -59,6 +59,6 @@ TrailingSlashConfig struct {
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
DefaultTrailingSlashConfig = TrailingSlashConfig{
|
DefaultTrailingSlashConfig = TrailingSlashConfig{
|
||||||
Skipper: defaultSkipper,
|
Skipper: DefaultSkipper,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user