LoadConfigFromEnv overrides current values with environment variables
(c *Config)
| 86 | |
| 87 | // LoadConfigFromEnv overrides current values with environment variables |
| 88 | func LoadConfigFromEnv(c *Config) (*Config, error) { |
| 89 | c = ensure.Ensure(c, NewDefaultConfig) |
| 90 | |
| 91 | _, rwErr := responsewriter.LoadConfigFromEnv(&c.ResponseWriter) |
| 92 | |
| 93 | port := -1 |
| 94 | bind := "" |
| 95 | |
| 96 | err := errors.Join( |
| 97 | rwErr, |
| 98 | PORT.Parse(&port), |
| 99 | IMGPROXY_BIND.Parse(&bind), |
| 100 | IMGPROXY_NETWORK.Parse(&c.Network), |
| 101 | IMGPROXY_PATH_PREFIX.Parse(&c.PathPrefix), |
| 102 | IMGPROXY_MAX_CLIENTS.Parse(&c.MaxClients), |
| 103 | IMGPROXY_TIMEOUT.Parse(&c.RequestTimeout), |
| 104 | IMGPROXY_READ_REQUEST_TIMEOUT.Parse(&c.ReadRequestTimeout), |
| 105 | IMGPROXY_KEEP_ALIVE_TIMEOUT.Parse(&c.KeepAliveTimeout), |
| 106 | IMGPROXY_GRACEFUL_STOP_TIMEOUT.Parse(&c.GracefulStopTimeout), |
| 107 | IMGPROXY_ALLOW_ORIGIN.Parse(&c.CORSAllowOrigin), |
| 108 | IMGPROXY_SECRET.Parse(&c.Secret), |
| 109 | IMGPROXY_DEVELOPMENT_ERRORS_MODE.Parse(&c.DevelopmentErrorsMode), |
| 110 | IMGPROXY_SO_REUSEPORT.Parse(&c.SocketReusePort), |
| 111 | IMGPROXY_HEALTH_CHECK_PATH.Parse(&c.HealthCheckPath), |
| 112 | IMGPROXY_FREE_MEMORY_INTERVAL.Parse(&c.FreeMemoryInterval), |
| 113 | IMGPROXY_LOG_MEM_STATS.Parse(&c.LogMemStats), |
| 114 | ) |
| 115 | |
| 116 | switch { |
| 117 | case len(bind) > 0: |
| 118 | c.Bind = bind |
| 119 | case port > -1: |
| 120 | c.Bind = fmt.Sprintf(":%d", port) |
| 121 | } |
| 122 | |
| 123 | return c, err |
| 124 | } |
| 125 | |
| 126 | // Validate checks that the config values are valid |
| 127 | func (c *Config) Validate() error { |
no test coverage detected