LoadFromEnv -> LoadConfigFromEnv

This commit is contained in:
DarthSim
2025-09-06 01:11:26 +03:00
parent 269e28bd62
commit a39890b00a
17 changed files with 47 additions and 47 deletions

View File

@@ -27,8 +27,8 @@ func NewDefaultConfig() *Config {
} }
} }
// LoadFromEnv loads config variables from env // LoadConfigFromEnv loads config variables from env
func LoadFromEnv(c *Config) (*Config, error) { func LoadConfigFromEnv(c *Config) (*Config, error) {
c.UserAgent = config.UserAgent c.UserAgent = config.UserAgent
c.DownloadTimeout = time.Duration(config.DownloadTimeout) * time.Second c.DownloadTimeout = time.Duration(config.DownloadTimeout) * time.Second
c.MaxRedirects = config.MaxRedirects c.MaxRedirects = config.MaxRedirects

View File

@@ -33,8 +33,8 @@ func NewDefaultConfig() *Config {
} }
} }
// LoadFromEnv loads config from environment variables // LoadConfigFromEnv loads config from environment variables
func LoadFromEnv(c *Config) (*Config, error) { func LoadConfigFromEnv(c *Config) (*Config, error) {
c.PathPrefix = config.PathPrefix c.PathPrefix = config.PathPrefix
c.CookiePassthrough = config.CookiePassthrough c.CookiePassthrough = config.CookiePassthrough
c.ReportDownloadingErrors = config.ReportDownloadingErrors c.ReportDownloadingErrors = config.ReportDownloadingErrors

View File

@@ -38,8 +38,8 @@ func NewDefaultConfig() *Config {
} }
} }
// LoadFromEnv loads config variables from environment // LoadConfigFromEnv loads config variables from environment
func LoadFromEnv(c *Config) (*Config, error) { func LoadConfigFromEnv(c *Config) (*Config, error) {
c.CookiePassthrough = config.CookiePassthrough c.CookiePassthrough = config.CookiePassthrough
return c, nil return c, nil
} }

View File

@@ -49,7 +49,7 @@ func (s *HandlerTestSuite) SetupTest() {
config.Reset() config.Reset()
config.AllowLoopbackSourceAddresses = true config.AllowLoopbackSourceAddresses = true
trc, err := transport.LoadFromEnv(transport.NewDefaultConfig()) trc, err := transport.LoadConfigFromEnv(transport.NewDefaultConfig())
s.Require().NoError(err) s.Require().NoError(err)
tr, err := transport.New(trc) tr, err := transport.New(trc)
@@ -349,7 +349,7 @@ func (s *HandlerTestSuite) TestHandlerCacheControl() {
})) }))
defer ts.Close() defer ts.Close()
trc, err := transport.LoadFromEnv(transport.NewDefaultConfig()) trc, err := transport.LoadConfigFromEnv(transport.NewDefaultConfig())
s.Require().NoError(err) s.Require().NoError(err)
// Create new handler with updated config for each test // Create new handler with updated config for each test
@@ -446,7 +446,7 @@ func (s *HandlerTestSuite) TestHandlerErrorResponse() {
// TestHandlerCookiePassthrough tests the cookie passthrough behavior of the streaming service. // TestHandlerCookiePassthrough tests the cookie passthrough behavior of the streaming service.
func (s *HandlerTestSuite) TestHandlerCookiePassthrough() { func (s *HandlerTestSuite) TestHandlerCookiePassthrough() {
trc, err := transport.LoadFromEnv(transport.NewDefaultConfig()) trc, err := transport.LoadConfigFromEnv(transport.NewDefaultConfig())
s.Require().NoError(err) s.Require().NoError(err)
// Create new handler with updated config // Create new handler with updated config
@@ -506,7 +506,7 @@ func (s *HandlerTestSuite) TestHandlerCanonicalHeader() {
defer ts.Close() defer ts.Close()
for _, sc := range []bool{true, false} { for _, sc := range []bool{true, false} {
trc, err := transport.LoadFromEnv(transport.NewDefaultConfig()) trc, err := transport.LoadConfigFromEnv(transport.NewDefaultConfig())
s.Require().NoError(err) s.Require().NoError(err)
// Create new handler with updated config // Create new handler with updated config

View File

@@ -28,8 +28,8 @@ func NewDefaultConfig() *Config {
} }
} }
// LoadFromEnv overrides configuration variables from environment // LoadConfigFromEnv overrides configuration variables from environment
func LoadFromEnv(c *Config) (*Config, error) { func LoadConfigFromEnv(c *Config) (*Config, error) {
c.SetCanonicalHeader = config.SetCanonicalHeader c.SetCanonicalHeader = config.SetCanonicalHeader
c.DefaultTTL = config.TTL c.DefaultTTL = config.TTL
c.FallbackImageTTL = config.FallbackImageTTL c.FallbackImageTTL = config.FallbackImageTTL

View File

@@ -70,13 +70,13 @@ func (s *ImageDataTestSuite) SetupSuite() {
rw.Write(data) rw.Write(data)
})) }))
ctr, err := transport.LoadFromEnv(transport.NewDefaultConfig()) ctr, err := transport.LoadConfigFromEnv(transport.NewDefaultConfig())
s.Require().NoError(err) s.Require().NoError(err)
ts, err := transport.New(ctr) ts, err := transport.New(ctr)
s.Require().NoError(err) s.Require().NoError(err)
c, err := fetcher.LoadFromEnv(fetcher.NewDefaultConfig()) c, err := fetcher.LoadConfigFromEnv(fetcher.NewDefaultConfig())
s.Require().NoError(err) s.Require().NoError(err)
fetcher, err := fetcher.New(ts, c) fetcher, err := fetcher.New(ts, c)

14
main.go
View File

@@ -46,7 +46,7 @@ const (
func callHandleProcessing(reqID string, rw http.ResponseWriter, r *http.Request) error { func callHandleProcessing(reqID string, rw http.ResponseWriter, r *http.Request) error {
// NOTE: This is temporary, will be moved level up at once // NOTE: This is temporary, will be moved level up at once
hwc, err := headerwriter.LoadFromEnv(headerwriter.NewDefaultConfig()) hwc, err := headerwriter.LoadConfigFromEnv(headerwriter.NewDefaultConfig())
if err != nil { if err != nil {
return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig)) return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig))
} }
@@ -56,12 +56,12 @@ func callHandleProcessing(reqID string, rw http.ResponseWriter, r *http.Request)
return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig)) return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig))
} }
sc, err := stream.LoadFromEnv(stream.NewDefaultConfig()) sc, err := stream.LoadConfigFromEnv(stream.NewDefaultConfig())
if err != nil { if err != nil {
return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig)) return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig))
} }
tcfg, err := transport.LoadFromEnv(transport.NewDefaultConfig()) tcfg, err := transport.LoadConfigFromEnv(transport.NewDefaultConfig())
if err != nil { if err != nil {
return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig)) return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig))
} }
@@ -71,7 +71,7 @@ func callHandleProcessing(reqID string, rw http.ResponseWriter, r *http.Request)
return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig)) return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig))
} }
fc, err := fetcher.LoadFromEnv(fetcher.NewDefaultConfig()) fc, err := fetcher.LoadConfigFromEnv(fetcher.NewDefaultConfig())
if err != nil { if err != nil {
return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig)) return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig))
} }
@@ -88,12 +88,12 @@ func callHandleProcessing(reqID string, rw http.ResponseWriter, r *http.Request)
return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig)) return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig))
} }
phc, err := processingHandler.LoadFromEnv(processingHandler.NewDefaultConfig()) phc, err := processingHandler.LoadConfigFromEnv(processingHandler.NewDefaultConfig())
if err != nil { if err != nil {
return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig)) return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig))
} }
semc, err := semaphores.LoadFromEnv(semaphores.NewDefaultConfig()) semc, err := semaphores.LoadConfigFromEnv(semaphores.NewDefaultConfig())
if err != nil { if err != nil {
return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig)) return ierrors.Wrap(err, 0, ierrors.WithCategory(categoryConfig))
} }
@@ -240,7 +240,7 @@ func run(ctx context.Context) error {
return err return err
} }
cfg, err := server.LoadFromEnv(server.NewDefaultConfig()) cfg, err := server.LoadConfigFromEnv(server.NewDefaultConfig())
if err != nil { if err != nil {
return err return err
} }

View File

@@ -108,13 +108,13 @@ func (s *ProcessingHandlerTestSuite) readTestImageData(name string) imagedata.Im
// because currently configuration is changed via env vars // because currently configuration is changed via env vars
// or config. We need to pick up those config changes. // or config. We need to pick up those config changes.
// This will be addressed in the next PR // This will be addressed in the next PR
trc, err := transport.LoadFromEnv(transport.NewDefaultConfig()) trc, err := transport.LoadConfigFromEnv(transport.NewDefaultConfig())
s.Require().NoError(err) s.Require().NoError(err)
tr, err := transport.New(trc) tr, err := transport.New(trc)
s.Require().NoError(err) s.Require().NoError(err)
fc, err := fetcher.LoadFromEnv(fetcher.NewDefaultConfig()) fc, err := fetcher.LoadConfigFromEnv(fetcher.NewDefaultConfig())
s.Require().NoError(err) s.Require().NoError(err)
f, err := fetcher.New(tr, fc) f, err := fetcher.New(tr, fc)

View File

@@ -21,8 +21,8 @@ func NewDefaultConfig() *Config {
} }
} }
// LoadFromEnv loads config from environment variables // LoadConfigFromEnv loads config from environment variables
func LoadFromEnv(c *Config) (*Config, error) { func LoadConfigFromEnv(c *Config) (*Config, error) {
c.RequestsQueueSize = config.RequestsQueueSize c.RequestsQueueSize = config.RequestsQueueSize
c.Workers = config.Workers c.Workers = config.Workers

View File

@@ -50,8 +50,8 @@ func NewDefaultConfig() *Config {
} }
} }
// LoadFromEnv overrides current values with environment variables // LoadConfigFromEnv overrides current values with environment variables
func LoadFromEnv(c *Config) (*Config, error) { func LoadConfigFromEnv(c *Config) (*Config, error) {
c.Network = config.Network c.Network = config.Network
c.Bind = config.Bind c.Bind = config.Bind
c.PathPrefix = config.PathPrefix c.PathPrefix = config.PathPrefix

View File

@@ -22,8 +22,8 @@ func NewDefaultConfig() *Config {
} }
} }
// LoadFromEnv loads configuration from the global config package // LoadConfigFromEnv loads configuration from the global config package
func LoadFromEnv(c *Config) (*Config, error) { func LoadConfigFromEnv(c *Config) (*Config, error) {
c.Name = config.ABSName c.Name = config.ABSName
c.Endpoint = config.ABSEndpoint c.Endpoint = config.ABSEndpoint
c.Key = config.ABSKey c.Key = config.ABSKey

View File

@@ -47,31 +47,31 @@ func NewDefaultConfig() *Config {
} }
} }
// LoadFromEnv loads transport configuration from environment variables // LoadConfigFromEnv loads transport configuration from environment variables
func LoadFromEnv(c *Config) (*Config, error) { func LoadConfigFromEnv(c *Config) (*Config, error) {
var err error var err error
if c.HTTP, err = generichttp.LoadFromEnv(c.HTTP); err != nil { if c.HTTP, err = generichttp.LoadConfigFromEnv(c.HTTP); err != nil {
return nil, err return nil, err
} }
if c.Local, err = fs.LoadFromEnv(c.Local); err != nil { if c.Local, err = fs.LoadConfigFromEnv(c.Local); err != nil {
return nil, err return nil, err
} }
if c.ABS, err = azure.LoadFromEnv(c.ABS); err != nil { if c.ABS, err = azure.LoadConfigFromEnv(c.ABS); err != nil {
return nil, err return nil, err
} }
if c.GCS, err = gcs.LoadFromEnv(c.GCS); err != nil { if c.GCS, err = gcs.LoadConfigFromEnv(c.GCS); err != nil {
return nil, err return nil, err
} }
if c.S3, err = s3.LoadFromEnv(c.S3); err != nil { if c.S3, err = s3.LoadConfigFromEnv(c.S3); err != nil {
return nil, err return nil, err
} }
if c.Swift, err = swift.LoadFromEnv(c.Swift); err != nil { if c.Swift, err = swift.LoadConfigFromEnv(c.Swift); err != nil {
return nil, err return nil, err
} }

View File

@@ -20,8 +20,8 @@ func NewDefaultConfig() *Config {
} }
} }
// LoadFromEnv loads configuration from the global config package // LoadConfigFromEnv loads configuration from the global config package
func LoadFromEnv(c *Config) (*Config, error) { func LoadConfigFromEnv(c *Config) (*Config, error) {
c.Root = config.LocalFileSystemRoot c.Root = config.LocalFileSystemRoot
return c, nil return c, nil

View File

@@ -16,8 +16,8 @@ func NewDefaultConfig() *Config {
} }
} }
// LoadFromEnv loads configuration from the global config package // LoadConfigFromEnv loads configuration from the global config package
func LoadFromEnv(c *Config) (*Config, error) { func LoadConfigFromEnv(c *Config) (*Config, error) {
c.Key = config.GCSKey c.Key = config.GCSKey
c.Endpoint = config.GCSEndpoint c.Endpoint = config.GCSEndpoint
return c, nil return c, nil

View File

@@ -21,8 +21,8 @@ func NewDefaultConfig() *Config {
} }
} }
// LoadFromEnv loads configuration from the global config package // LoadConfigFromEnv loads configuration from the global config package
func LoadFromEnv(c *Config) (*Config, error) { func LoadConfigFromEnv(c *Config) (*Config, error) {
c.ClientKeepAliveTimeout = time.Duration(config.ClientKeepAliveTimeout) * time.Second c.ClientKeepAliveTimeout = time.Duration(config.ClientKeepAliveTimeout) * time.Second
c.IgnoreSslVerification = config.IgnoreSslVerification c.IgnoreSslVerification = config.IgnoreSslVerification

View File

@@ -24,8 +24,8 @@ func NewDefaultConfig() *Config {
} }
} }
// LoadFromEnv loads configuration from the global config package // LoadConfigFromEnv loads configuration from the global config package
func LoadFromEnv(c *Config) (*Config, error) { func LoadConfigFromEnv(c *Config) (*Config, error) {
c.Region = config.S3Region c.Region = config.S3Region
c.Endpoint = config.S3Endpoint c.Endpoint = config.S3Endpoint
c.EndpointUsePathStyle = config.S3EndpointUsePathStyle c.EndpointUsePathStyle = config.S3EndpointUsePathStyle

View File

@@ -32,8 +32,8 @@ func NewDefaultConfig() *Config {
} }
} }
// LoadFromEnv loads configuration from the global config package // LoadConfigFromEnv loads configuration from the global config package
func LoadFromEnv(c *Config) (*Config, error) { func LoadConfigFromEnv(c *Config) (*Config, error) {
c.Username = config.SwiftUsername c.Username = config.SwiftUsername
c.APIKey = config.SwiftAPIKey c.APIKey = config.SwiftAPIKey
c.AuthURL = config.SwiftAuthURL c.AuthURL = config.SwiftAuthURL