1
0
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:
Vishal Rana 2017-03-05 19:08:11 -08:00
parent 948d607539
commit 6bb7747530
16 changed files with 90 additions and 15 deletions

View File

@ -1,8 +1,12 @@
package echo
import (
"path"
)
type (
// 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.
Group struct {
prefix string
@ -16,7 +20,7 @@ func (g *Group) Use(middleware ...MiddlewareFunc) {
g.middleware = append(g.middleware, middleware...)
// 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.
g.echo.Any(g.prefix+"/*", func(c Context) error {
g.echo.Any(path.Clean(g.prefix+"/*"), func(c Context) error {
return ErrNotFound
}, g.middleware...)
}

View File

@ -9,6 +9,8 @@ description = "Serving static files in Echo"
Images, JavaScript, CSS, PDF, Fonts and so on...
## [Using Static Middleware]({{< ref "middleware/static.md">}})
## Using `Echo#Static()`
`Echo#Static(prefix, root string)` registers a new route with path prefix to serve

View File

@ -52,6 +52,6 @@ BasicAuthConfig struct {
```go
DefaultBasicAuthConfig = BasicAuthConfig{
Skipper: defaultSkipper,
Skipper: DefaultSkipper,
}
```

View File

@ -48,6 +48,6 @@ BodyLimitConfig struct {
```go
DefaultBodyLimitConfig = BodyLimitConfig{
Skipper: defaultSkipper,
Skipper: DefaultSkipper,
}
```

View File

@ -72,7 +72,7 @@ CORSConfig struct {
```go
DefaultCORSConfig = CORSConfig{
Skipper: defaultSkipper,
Skipper: DefaultSkipper,
AllowOrigins: []string{"*"},
AllowMethods: []string{echo.GET, echo.HEAD, echo.PUT, echo.PATCH, echo.POST, echo.DELETE},
}

View File

@ -95,7 +95,7 @@ CSRFConfig struct {
```go
DefaultCSRFConfig = CSRFConfig{
Skipper: defaultSkipper,
Skipper: DefaultSkipper,
TokenLength: 32,
TokenLookup: "header:" + echo.HeaderXCSRFToken,
ContextKey: "csrf",

View File

@ -41,7 +41,7 @@ GzipConfig struct {
```go
DefaultGzipConfig = GzipConfig{
Skipper: defaultSkipper,
Skipper: DefaultSkipper,
Level: -1,
}
```

View File

@ -71,7 +71,7 @@ JWTConfig struct {
```go
DefaultJWTConfig = JWTConfig{
Skipper: defaultSkipper,
Skipper: DefaultSkipper,
SigningMethod: AlgorithmHS256,
ContextKey: "user",
TokenLookup: "header:" + echo.HeaderAuthorization,

View File

@ -62,7 +62,7 @@ KeyAuthConfig struct {
```go
DefaultKeyAuthConfig = KeyAuthConfig{
Skipper: defaultSkipper,
Skipper: DefaultSkipper,
KeyLookup: "header:" + echo.HeaderAuthorization,
AuthScheme: "Bearer",
}

View File

@ -83,7 +83,7 @@ LoggerConfig struct {
```go
DefaultLoggerConfig = LoggerConfig{
Skipper: defaultSkipper,
Skipper: DefaultSkipper,
Format: `{"time":"${time_rfc3339_nano}","remote_ip":"${remote_ip}","host":"${host}",` +
`"method":"${method}","uri":"${uri}","status":${status}, "latency":${latency},` +
`"latency_human":"${latency_human}","bytes_in":${bytes_in},` +

View File

@ -44,7 +44,7 @@ MethodOverrideConfig struct {
```go
DefaultMethodOverrideConfig = MethodOverrideConfig{
Skipper: defaultSkipper,
Skipper: DefaultSkipper,
Getter: MethodFromHeader(echo.HeaderXHTTPMethodOverride),
}
```

View File

@ -55,7 +55,7 @@ RecoverConfig struct {
```go
DefaultRecoverConfig = RecoverConfig{
Skipper: defaultSkipper,
Skipper: DefaultSkipper,
StackSize: 4 << 10, // 4 KB
DisableStackAll: false,
DisablePrintStack: false,

View File

@ -98,7 +98,7 @@ RedirectConfig struct {
```go
DefaultRedirectConfig = RedirectConfig{
Skipper: defaultSkipper,
Skipper: DefaultSkipper,
Code: http.StatusMovedPermanently,
}
```

View File

@ -88,7 +88,7 @@ SecureConfig struct {
```go
DefaultSecureConfig = SecureConfig{
Skipper: defaultSkipper,
Skipper: DefaultSkipper,
XSSProtection: "1; mode=block",
ContentTypeNosniff: "nosniff",
XFrameOptions: "SAMEORIGIN",

View 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",
}
```

View File

@ -59,6 +59,6 @@ TrailingSlashConfig struct {
```go
DefaultTrailingSlashConfig = TrailingSlashConfig{
Skipper: defaultSkipper,
Skipper: DefaultSkipper,
}
```