72 lines
1.1 KiB
Go
72 lines
1.1 KiB
Go
package http
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
const DefaultPrefix = "Http"
|
|
|
|
type Config struct {
|
|
Host string
|
|
Port uint
|
|
|
|
StaticPath *string
|
|
StaticRoute *string
|
|
BaseURI *string
|
|
TLS *TLS
|
|
Cors *Cors
|
|
RateLimit *RateLimit
|
|
}
|
|
|
|
type TLS struct {
|
|
Cert string
|
|
Key string
|
|
}
|
|
|
|
type Cors struct {
|
|
Mode string
|
|
Whitelist []Whitelist
|
|
}
|
|
|
|
type RateLimit struct {
|
|
Enabled bool
|
|
Max int
|
|
WindowSeconds int
|
|
Message string
|
|
SkipPaths []string
|
|
Redis *RateLimitRedis
|
|
}
|
|
|
|
type RateLimitRedis struct {
|
|
Addrs []string
|
|
Username string
|
|
Password string
|
|
DB int
|
|
Prefix string
|
|
}
|
|
|
|
type Whitelist struct {
|
|
AllowOrigin string
|
|
AllowHeaders string
|
|
AllowMethods string
|
|
ExposeHeaders string
|
|
AllowCredentials bool
|
|
}
|
|
|
|
func (h *Config) Address() string {
|
|
if h.Host == "" {
|
|
return fmt.Sprintf("0.0.0.0:%d", h.Port)
|
|
}
|
|
|
|
return fmt.Sprintf("%s:%d", h.Host, h.Port)
|
|
}
|
|
|
|
func (h *Config) HasTLS() bool {
|
|
if h == nil || h.TLS == nil {
|
|
return false
|
|
}
|
|
|
|
return strings.TrimSpace(h.TLS.Cert) != "" && strings.TrimSpace(h.TLS.Key) != ""
|
|
}
|