static_config.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package auximageprovider
  2. import (
  3. "github.com/imgproxy/imgproxy/v3/config"
  4. "github.com/imgproxy/imgproxy/v3/ensure"
  5. )
  6. // StaticConfig holds the configuration for the auxiliary image provider
  7. type StaticConfig struct {
  8. Base64Data string
  9. Path string
  10. URL string
  11. }
  12. // NewDefaultStaticConfig creates a new default configuration for the auxiliary image provider
  13. func NewDefaultStaticConfig() StaticConfig {
  14. return StaticConfig{
  15. Base64Data: "",
  16. Path: "",
  17. URL: "",
  18. }
  19. }
  20. // LoadWatermarkStaticConfigFromEnv loads the watermark configuration from the environment
  21. func LoadWatermarkStaticConfigFromEnv(c *StaticConfig) (*StaticConfig, error) {
  22. c = ensure.Ensure(c, NewDefaultStaticConfig)
  23. c.Base64Data = config.WatermarkData
  24. c.Path = config.WatermarkPath
  25. c.URL = config.WatermarkURL
  26. return c, nil
  27. }
  28. // LoadFallbackStaticConfigFromEnv loads the fallback configuration from the environment
  29. func LoadFallbackStaticConfigFromEnv(c *StaticConfig) (*StaticConfig, error) {
  30. c = ensure.Ensure(c, NewDefaultStaticConfig)
  31. c.Base64Data = config.FallbackImageData
  32. c.Path = config.FallbackImagePath
  33. c.URL = config.FallbackImageURL
  34. return c, nil
  35. }