Update README.md

pull/6/head
Fenny 2020-01-16 10:17:48 +01:00 committed by GitHub
parent 13c8cb2c95
commit d58ff74b38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 9 deletions

View File

@ -54,20 +54,40 @@ import "github.com/gofiber/fiber"
func main() {
app := fiber.New()
app.Get("/static", func(c *fiber.Ctx) {
c.Set("X-XSS-Protection", "1; mode=block")
c.Next()
})
app.Static("/static", ./public")
app.Static("./public")
app.Listen(8080)
}
```
Now, you can load the files that are in the public directory:
```shell
http://localhost:8080/static/images/gopher.png
http://localhost:8080/static/css/style.css
http://localhost:8080/static/js/jquery.js
http://localhost:8080/static/hello.html
http://localhost:8080/images/gopher.png
http://localhost:8080/css/style.css
http://localhost:8080/js/jquery.js
http://localhost:8080/hello.html
```
## Middleware
Middleware never has been so easy!
```go
package main
import "github.com/gofiber/fiber"
func main() {
app := fiber.New()
app.Get("/api*", func(c *fiber.Ctx) {
c.Locals("auth", "admin")
c.Next()
})
app.Get("/api/back-end/:action?", func(c *fiber.Ctx) {
if c.Locals("auth") != "admin {
c.Status(403).Send("Forbidden")
return
}
c.Send("Hello, Admin!")
})
app.Listen(8080)
}
```
## API Documentation