config.go 1015 B

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