1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-23 20:03:43 +00:00

✏ update config

This commit is contained in:
Fenny 2020-11-11 18:49:07 +01:00
parent d8623ef53c
commit 75e3f13de1
2 changed files with 54 additions and 9 deletions

View File

@ -18,18 +18,32 @@ Import the middleware package that is part of the Fiber web framework
```go
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/gofiber/fiber/v2/middleware/session"
)
```
After you initiate your Fiber app, you can use the following possibilities:
```go
// Default middleware config
app.Use(recover.New())
store := session.New()
// This panic will be catch by the middleware
app.Get("/", func(c *fiber.Ctx) error {
panic("I'm an error")
sess := store.Get(c)
defer sess.Save()
// Get value
name := sess.Get("name")
fmt.Println(val)
// Set key/value
sess.Set("name", "john")
// Delete key
sess.Delete("name")
return fmt.Fprintf(ctx, "Welcome %v", name)
})
```
@ -37,16 +51,47 @@ app.Get("/", func(c *fiber.Ctx) error {
```go
// Config defines the config for middleware.
type Config struct {
// Next defines a function to skip this middleware when returned true.
// Possible values:
// - "header:<name>"
// - "query:<name>"
// - "param:<name>"
// - "form:<name>"
// - "cookie:<name>"
//
// Optional. Default: nil
Next func(c *fiber.Ctx) bool
// Optional. Default value "cookie:_csrf".
// TODO: When to override Cookie.Value?
KeyLookup string
// Optional. Session ID generator function.
//
// Default: utils.UUID
KeyGenerator func() string
// Optional. Cookie to set values on
//
// NOTE: Value, MaxAge and Expires will be overriden by the session ID and expiration
// TODO: Should this be a pointer, if yes why?
Cookie fiber.Cookie
// Allowed session duration
//
// Optional. Default: 24 * time.Hour
Expiration time.Duration
// Storage interface
//
// Optional. Default: memory.New()
Storage fiber.Storage
}
```
### Default Config
```go
var ConfigDefault = Config{
Next: nil,
Cookie: fiber.Cookie{
Value: "session_id",
},
Expiration: 24 * time.Hour,
KeyGenerator: utils.UUID,
}
```

View File

@ -34,7 +34,7 @@ type Config struct {
// Allowed session duration
//
// Optional. Default: 24 hours
// Optional. Default: 24 * time.Hour
Expiration time.Duration
// Storage interface
@ -48,7 +48,7 @@ var ConfigDefault = Config{
Cookie: fiber.Cookie{
Value: "session_id",
},
Expiration: 30 * time.Minute,
Expiration: 24 * time.Hour,
KeyGenerator: utils.UUID,
}