config.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package pipeline
  2. import (
  3. "errors"
  4. "github.com/imgproxy/imgproxy/v3/config"
  5. "github.com/imgproxy/imgproxy/v3/ensure"
  6. )
  7. // Config holds pipeline-related configuration.
  8. type Config struct {
  9. WatermarkOpacity float64
  10. DisableShrinkOnLoad bool
  11. UseLinearColorspace bool
  12. }
  13. // NewConfig creates a new Config instance with the given parameters.
  14. func NewDefaultConfig() Config {
  15. return Config{
  16. WatermarkOpacity: 1,
  17. }
  18. }
  19. // NewConfig creates a new Config instance with the given parameters.
  20. func LoadConfigFromEnv(c *Config) (*Config, error) {
  21. c = ensure.Ensure(c, NewDefaultConfig)
  22. c.WatermarkOpacity = config.WatermarkOpacity
  23. c.DisableShrinkOnLoad = config.DisableShrinkOnLoad
  24. c.UseLinearColorspace = config.UseLinearColorspace
  25. return c, nil
  26. }
  27. // Validate checks if the configuration is valid
  28. func (c *Config) Validate() error {
  29. if c.WatermarkOpacity <= 0 {
  30. return errors.New("watermark opacity should be greater than 0")
  31. } else if c.WatermarkOpacity > 1 {
  32. return errors.New("watermark opacity should be less than or equal to 1")
  33. }
  34. return nil
  35. }