config.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package guerrilla
  2. import "strings"
  3. type BackendConfig map[string]interface{}
  4. // Config is the holder of the configuration of the app
  5. type Config struct {
  6. BackendName string `json:"backend_name"`
  7. BackendConfig BackendConfig `json:"backend_config,omitempty"`
  8. Servers []ServerConfig `json:"servers"`
  9. AllowedHosts string `json:"allowed_hosts"`
  10. _allowedHosts map[string]bool
  11. }
  12. func (c *Config) IsAllowed(host string) bool {
  13. if c._allowedHosts == nil {
  14. arr := strings.Split(c.AllowedHosts, ",")
  15. c._allowedHosts = make(map[string]bool, len(arr))
  16. for _, h := range arr {
  17. c._allowedHosts[strings.ToLower(h)] = true
  18. }
  19. }
  20. return c._allowedHosts[strings.ToLower(host)]
  21. }
  22. // ServerConfig is the holder of the configuration of a server
  23. type ServerConfig struct {
  24. IsEnabled bool `json:"is_enabled"`
  25. Hostname string `json:"host_name"`
  26. MaxSize int `json:"max_size"`
  27. PrivateKeyFile string `json:"private_key_file"`
  28. PublicKeyFile string `json:"public_key_file"`
  29. Timeout int `json:"timeout"`
  30. ListenInterface string `json:"listen_interface"`
  31. StartTLS bool `json:"start_tls_on,omitempty"`
  32. TLSAlwaysOn bool `json:"tls_always_on,omitempty"`
  33. MaxClients int `json:"max_clients"`
  34. }