1
0

config.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package cookies
  2. import (
  3. "errors"
  4. "github.com/imgproxy/imgproxy/v3/ensure"
  5. "github.com/imgproxy/imgproxy/v3/env"
  6. )
  7. var (
  8. IMGPROXY_COOKIE_PASSTHROUGH = env.Describe("IMGPROXY_COOKIE_PASSTHROUGH", "boolean")
  9. IMGPROXY_COOKIE_PASSTHROUGH_ALL = env.Describe("IMGPROXY_COOKIE_PASSTHROUGH_ALL", "boolean")
  10. IMGPROXY_COOKIE_BASE_URL = env.Describe("IMGPROXY_COOKIE_BASE_URL", "string")
  11. )
  12. // Config holds cookie-related configuration.
  13. type Config struct {
  14. CookiePassthrough bool
  15. CookiePassthroughAll bool
  16. CookieBaseURL string
  17. }
  18. // NewDefaultConfig creates a new Config instance with default values.
  19. func NewDefaultConfig() Config {
  20. return Config{
  21. CookiePassthroughAll: false,
  22. CookieBaseURL: "",
  23. CookiePassthrough: false,
  24. }
  25. }
  26. // LoadConfigFromEnv creates a new Config instance loading values from environment variables.
  27. func LoadConfigFromEnv(c *Config) (*Config, error) {
  28. c = ensure.Ensure(c, NewDefaultConfig)
  29. err := errors.Join(
  30. env.Bool(&c.CookiePassthrough, IMGPROXY_COOKIE_PASSTHROUGH),
  31. env.Bool(&c.CookiePassthroughAll, IMGPROXY_COOKIE_PASSTHROUGH_ALL),
  32. env.String(&c.CookieBaseURL, IMGPROXY_COOKIE_BASE_URL),
  33. )
  34. return c, err
  35. }
  36. // Validate checks if the configuration is valid
  37. func (c *Config) Validate() error {
  38. // No validation needed for cookie config currently
  39. return nil
  40. }