do basicauth, cache and compress

pull/1027/head
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
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. 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 ## Table of Contents
- [Basic Authentication](#basic-authentication)
- [Table of Contents](#table-of-contents)
- [Signatures](#signatures) - [Signatures](#signatures)
- [Examples](#examples) - [Examples](#examples)
- [Custom Config](#custom-config)
- [Config](#config) - [Config](#config)
- [Default Config](#default-config) - [Default Config](#default-config)
### Signatures ## Signatures
```go ```go
func New(config Config) fiber.Handler func New(config Config) fiber.Handler
``` ```
### Examples ## Examples
Import the middleware package that is part of the Fiber web framework First import the middleware from Fiber,
```go ```go
import ( import (
"github.com/gofiber/fiber/v2" "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 ```go
// Provide a minimal config // Provide a minimal config
app.Use(basicauth.New(basicauth.Config{ app.Use(basicauth.New(basicauth.Config{
@ -56,7 +63,7 @@ app.Use(basicauth.New(basicauth.Config{
})) }))
``` ```
### Config ## Config
```go ```go
// Config defines the config for middleware. // Config defines the config for middleware.
type Config struct { type Config struct {
@ -104,7 +111,7 @@ type Config struct {
} }
``` ```
### Default Config ## Default Config
```go ```go
var ConfigDefault = Config{ var ConfigDefault = Config{
Next: nil, Next: nil,

View File

@ -1,20 +1,25 @@
# Cache # 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 ## Table of Contents
- [Cache](#cache)
- [Table of Contents](#table-of-contents)
- [Signatures](#signatures) - [Signatures](#signatures)
- [Examples](#examples) - [Examples](#examples)
- [Config](#config)
- [Default Config](#default-config) - [Default Config](#default-config)
- [Custom Config](#custom-config)
- [Config](#config)
- [Default Config](#default-config-1)
### Signatures ## Signatures
```go ```go
func New(config ...Config) fiber.Handler func New(config ...Config) fiber.Handler
``` ```
### Examples ## Examples
Import the middleware package that is part of the Fiber web framework First import the middleware from Fiber,
```go ```go
import ( import (
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
@ -22,12 +27,16 @@ import (
) )
``` ```
After you initiate your Fiber app, you can use the following possibilities: Then create a Fiber app with `app := fiber.New()`.
```go
// Initialize default config
app.Use(cache.New())
// Or extend your config for customization ### Default Config
```go
app.Use(cache.New())
```
### Custom Config
```go
app.Use(cache.New(cache.Config{ app.Use(cache.New(cache.Config{
Next: func(c *fiber.Ctx) bool { Next: func(c *fiber.Ctx) bool {
return c.Query("refresh") == "true" return c.Query("refresh") == "true"

View File

@ -1,20 +1,24 @@
# Compress # 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. 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.
- [Compress](#compress)
- [Signatures](#signatures) - [Signatures](#signatures)
- [Examples](#examples) - [Examples](#examples)
- [Config](#config)
- [Default Config](#default-config) - [Default Config](#default-config)
- [Constants](#config) - [Custom Config](#custom-config)
- [Config](#config)
- [Default Config](#default-config-1)
- [Constants](#constants)
### Signatures ## Signatures
```go ```go
func New(config ...Config) fiber.Handler func New(config ...Config) fiber.Handler
``` ```
### Examples ## Examples
Import the middleware package that is part of the Fiber web framework First import the middleware from Fiber,
```go ```go
import ( import (
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
@ -22,11 +26,16 @@ import (
) )
``` ```
After you initiate your Fiber app, you can use the following possibilities: Then create a Fiber app with `app := fiber.New()`.
```go
// Default middleware config
app.Use(compress.New())
### Default Config
```go
app.Use(compress.New())
```
### Custom Config
```go
// Provide a custom compression level // Provide a custom compression level
app.Use(compress.New(compress.Config{ app.Use(compress.New(compress.Config{
Level: compress.LevelBestSpeed, // 1 Level: compress.LevelBestSpeed, // 1
@ -41,7 +50,7 @@ app.Use(compress.New(compress.Config{
})) }))
``` ```
### Config ## Config
```go ```go
// Config defines the config for middleware. // Config defines the config for middleware.
type Config struct { type Config struct {
@ -61,7 +70,7 @@ type Config struct {
} }
``` ```
### Default Config ## Default Config
```go ```go
var ConfigDefault = Config{ var ConfigDefault = Config{
Next: nil, Next: nil,
@ -69,7 +78,7 @@ var ConfigDefault = Config{
} }
``` ```
### Constants ## Constants
```go ```go
// Compression levels // Compression levels
const ( const (