config.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package gcs
  2. import (
  3. "errors"
  4. "github.com/imgproxy/imgproxy/v3/ensure"
  5. "github.com/imgproxy/imgproxy/v3/env"
  6. )
  7. var (
  8. IMGPROXY_GCS_KEY = env.Describe("IMGPROXY_GCS_KEY", "string")
  9. IMGPROXY_GCS_ENDPOINT = env.Describe("IMGPROXY_GCS_ENDPOINT", "string")
  10. )
  11. // Config holds the configuration for Google Cloud Storage transport
  12. type Config struct {
  13. Key string // Google Cloud Storage service account key
  14. Endpoint string // Google Cloud Storage endpoint URL
  15. }
  16. // NewDefaultConfig returns a new default configuration for Google Cloud Storage transport
  17. func NewDefaultConfig() Config {
  18. return Config{
  19. Key: "",
  20. Endpoint: "",
  21. }
  22. }
  23. // LoadConfigFromEnv loads configuration from the global config package
  24. func LoadConfigFromEnv(c *Config) (*Config, error) {
  25. c = ensure.Ensure(c, NewDefaultConfig)
  26. err := errors.Join(
  27. env.String(&c.Key, IMGPROXY_GCS_KEY),
  28. env.String(&c.Endpoint, IMGPROXY_GCS_ENDPOINT),
  29. )
  30. return c, err
  31. }
  32. // Validate checks the configuration for errors
  33. func (c *Config) Validate() error {
  34. return nil
  35. }