MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / loadLocalFile

Function loadLocalFile

env/load.go:37–58  ·  view source on GitHub ↗

loadLocalFile loads environment variables from a local file if IMGPROXY_ENV_LOCAL_FILE_PATH is set

()

Source from the content-addressed store, hash-verified

35
36// loadLocalFile loads environment variables from a local file if IMGPROXY_ENV_LOCAL_FILE_PATH is set
37func loadLocalFile() error {
38 var path string
39
40 IMGPROXY_ENV_LOCAL_FILE_PATH.Parse(&path)
41
42 if len(path) == 0 {
43 return nil
44 }
45
46 // Read the local environment file
47 data, err := os.ReadFile(path)
48 if err != nil {
49 return fmt.Errorf("can't read local environment file: %w", err)
50 }
51
52 // If the file is empty, nothing to load
53 if len(data) == 0 {
54 return nil
55 }
56
57 return unmarshalEnv(string(data), "local file")
58}
59
60// unmarshalEnv loads environment variables from a string to process environment
61func unmarshalEnv(env, source string) error {

Callers 1

LoadFunction · 0.85

Calls 3

unmarshalEnvFunction · 0.85
ParseMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected