mirror of https://github.com/gofiber/fiber.git
Update README.md
parent
13c8cb2c95
commit
d58ff74b38
38
README.md
38
README.md
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue