mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-24 04:24:02 +00:00
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package proxy
|
|
|
|
import (
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
// Config defines the config for middleware.
|
|
type Config struct {
|
|
// Next defines a function to skip this middleware when returned true.
|
|
//
|
|
// Optional. Default: nil
|
|
Next func(c *fiber.Ctx) bool
|
|
|
|
// Servers defines a list of <scheme>://<host> HTTP servers,
|
|
//
|
|
// which are used in a round-robin manner.
|
|
// i.e.: "https://foobar.com, http://www.foobar.com"
|
|
//
|
|
// Required
|
|
Servers []string
|
|
|
|
// ModifyRequest allows you to alter the request
|
|
//
|
|
// Optional. Default: nil
|
|
ModifyRequest fiber.Handler
|
|
|
|
// ModifyResponse allows you to alter the response
|
|
//
|
|
// Optional. Default: nil
|
|
ModifyResponse fiber.Handler
|
|
}
|
|
|
|
// ConfigDefault is the default config
|
|
var ConfigDefault = Config{
|
|
Next: nil,
|
|
ModifyRequest: nil,
|
|
ModifyResponse: nil,
|
|
}
|
|
|
|
// Helper function to set default values
|
|
func configDefault(config ...Config) Config {
|
|
// Return default config if nothing provided
|
|
if len(config) < 1 {
|
|
return ConfigDefault
|
|
}
|
|
|
|
// Override default config
|
|
cfg := config[0]
|
|
|
|
// Set default values
|
|
if len(cfg.Servers) == 0 {
|
|
panic("Servers cannot be empty")
|
|
}
|
|
return cfg
|
|
}
|