1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-19 12:47:54 +00:00

do basicauth, cache and compress

This commit is contained in:
hi019 2020-11-21 12:23:35 -05:00
parent e828c17554
commit 52ec20c3b4
3 changed files with 67 additions and 42 deletions

View File

@ -1,20 +1,24 @@
# Basic Authentication
Basic Authentication middleware for [Fiber](https://github.com/gofiber/fiber) that provides an HTTP basic authentication. It calls the next handler for valid credentials and [401 Unauthorized](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401) or a custom response for missing or invalid credentials.
### Table of Contents
- [Signatures](#signatures)
- [Examples](#examples)
- [Config](#config)
- [Default Config](#default-config)
## Table of Contents
- [Basic Authentication](#basic-authentication)
- [Table of Contents](#table-of-contents)
- [Signatures](#signatures)
- [Examples](#examples)
- [Custom Config](#custom-config)
- [Config](#config)
- [Default Config](#default-config)
### Signatures
## Signatures
```go
func New(config Config) fiber.Handler
```
### Examples
Import the middleware package that is part of the Fiber web framework
## Examples
First import the middleware from Fiber,
```go
import (
"github.com/gofiber/fiber/v2"
@ -22,7 +26,10 @@ import (
)
```
After you initiate your Fiber app, you can use the following possibilities:
Then create a Fiber app with `app := fiber.New()`.
### Custom Config
```go
// Provide a minimal config
app.Use(basicauth.New(basicauth.Config{
@ -56,7 +63,7 @@ app.Use(basicauth.New(basicauth.Config{
}))
```
### Config
## Config
```go
// Config defines the config for middleware.
type Config struct {
@ -104,7 +111,7 @@ type Config struct {
}
```
### Default Config
## Default Config
```go
var ConfigDefault = Config{
Next: nil,

View File

@ -1,33 +1,42 @@
# Cache
Cache middleware for [Fiber](https://github.com/gofiber/fiber) designed to intercept responses and cache them. This middleware will cache the `Body`, `Content-Type` and `StatusCode` using the `c.Path()` as unique identifier. Special thanks to [@codemicro](https://github.com/codemicro/fiber-cache) for creating this middleware for Fiber core!
Cache middleware for [Fiber](https://github.com/gofiber/fiber) designed to intercept responses and cache them. This middleware will cache the `Body`, `Content-Type` and `StatusCode` using the `c.Path()` (or a string returned by the Key function) as unique identifier. Special thanks to [@codemicro](https://github.com/codemicro/fiber-cache) for creating this middleware for Fiber core!
### Table of Contents
- [Signatures](#signatures)
- [Examples](#examples)
- [Config](#config)
- [Default Config](#default-config)
## Table of Contents
- [Cache](#cache)
- [Table of Contents](#table-of-contents)
- [Signatures](#signatures)
- [Examples](#examples)
- [Default Config](#default-config)
- [Custom Config](#custom-config)
- [Config](#config)
- [Default Config](#default-config-1)
### Signatures
## Signatures
```go
func New(config ...Config) fiber.Handler
```
### Examples
Import the middleware package that is part of the Fiber web framework
## Examples
First import the middleware from Fiber,
```go
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cache"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cache"
)
```
After you initiate your Fiber app, you can use the following possibilities:
```go
// Initialize default config
app.Use(cache.New())
Then create a Fiber app with `app := fiber.New()`.
// Or extend your config for customization
### Default Config
```go
app.Use(cache.New())
```
### Custom Config
```go
app.Use(cache.New(cache.Config{
Next: func(c *fiber.Ctx) bool {
return c.Query("refresh") == "true"

View File

@ -1,20 +1,24 @@
# Compress
Compression middleware for [Fiber](https://github.com/gofiber/fiber) that will compress the response using `gzip`, `deflate` and `brotli` compression depending on the [Accept-Encoding](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding) header.
- [Signatures](#signatures)
- [Examples](#examples)
- [Config](#config)
- [Default Config](#default-config)
- [Constants](#config)
- [Compress](#compress)
- [Signatures](#signatures)
- [Examples](#examples)
- [Default Config](#default-config)
- [Custom Config](#custom-config)
- [Config](#config)
- [Default Config](#default-config-1)
- [Constants](#constants)
### Signatures
## Signatures
```go
func New(config ...Config) fiber.Handler
```
### Examples
Import the middleware package that is part of the Fiber web framework
## Examples
First import the middleware from Fiber,
```go
import (
"github.com/gofiber/fiber/v2"
@ -22,11 +26,16 @@ import (
)
```
After you initiate your Fiber app, you can use the following possibilities:
```go
// Default middleware config
app.Use(compress.New())
Then create a Fiber app with `app := fiber.New()`.
### Default Config
```go
app.Use(compress.New())
```
### Custom Config
```go
// Provide a custom compression level
app.Use(compress.New(compress.Config{
Level: compress.LevelBestSpeed, // 1
@ -41,7 +50,7 @@ app.Use(compress.New(compress.Config{
}))
```
### Config
## Config
```go
// Config defines the config for middleware.
type Config struct {
@ -61,7 +70,7 @@ type Config struct {
}
```
### Default Config
## Default Config
```go
var ConfigDefault = Config{
Next: nil,
@ -69,7 +78,7 @@ var ConfigDefault = Config{
}
```
### Constants
## Constants
```go
// Compression levels
const (