include.go 794 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package httpserver
  2. import (
  3. "encoding/json"
  4. "os"
  5. )
  6. type HttpServerConfig struct {
  7. HttpPort int `json:"http_port"`
  8. HttpsPort int `json:"https_port"`
  9. AllowedDomain string `json:"allowed_domain"`
  10. UserAgent string `json:"user_agent"`
  11. UseSsl bool `json:"use_ssl"`
  12. }
  13. type Cookie struct {
  14. Name string `json:"name"`
  15. Value string `json:"value"`
  16. MaxAge int `json:"max_age"`
  17. Path string `json:"path"`
  18. Domain string `json:"domain"`
  19. Secure bool `json:"secure"`
  20. HttpOnly bool `json:"http_only"`
  21. }
  22. func ReadConfig(loc string) (*HttpServerConfig, error) {
  23. f, err := os.ReadFile(loc)
  24. if err != nil {
  25. return nil, err
  26. }
  27. var cfg HttpServerConfig
  28. err = json.Unmarshal(f, &cfg)
  29. if err != nil {
  30. return nil, err
  31. }
  32. return &cfg, err
  33. }