MCPcopy Index your code
hub / github.com/screego/server / Get

Function Get

config/config.go:102–242  ·  view source on GitHub ↗

Get loads the application config.

()

Source from the content-addressed store, hash-verified

100
101// Get loads the application config.
102func Get() (Config, []FutureLog) {
103 var logs []FutureLog
104 dir, log := getExecutableOrWorkDir()
105 if log != nil {
106 logs = append(logs, *log)
107 }
108
109 for _, file := range getFiles(dir) {
110 _, fileErr := osStat(file)
111 if fileErr == nil {
112 if err := godotenv.Load(file); err != nil {
113 logs = append(logs, futureFatal(fmt.Sprintf("cannot load file %s: %s", file, err)))
114 } else {
115 logs = append(logs, FutureLog{
116 Level: zerolog.DebugLevel,
117 Msg: fmt.Sprintf("Loading file %s", file),
118 })
119 }
120 } else if os.IsNotExist(fileErr) {
121 continue
122 } else {
123 logs = append(logs, FutureLog{
124 Level: zerolog.WarnLevel,
125 Msg: fmt.Sprintf("cannot read file %s because %s", file, fileErr),
126 })
127 }
128 }
129
130 config := Config{}
131 err := envconfig.Process(prefix, &config)
132 if err != nil {
133 logs = append(logs,
134 futureFatal(fmt.Sprintf("cannot parse env params: %s", err)))
135 }
136
137 if config.AuthMode != AuthModeTurn && config.AuthMode != AuthModeAll && config.AuthMode != AuthModeNone {
138 logs = append(logs,
139 futureFatal(fmt.Sprintf("invalid SCREEGO_AUTH_MODE: %s", config.AuthMode)))
140 }
141
142 if config.ServerTLS {
143 if config.TLSCertFile == "" {
144 logs = append(logs, futureFatal("SCREEGO_TLS_CERT_FILE must be set if TLS is enabled"))
145 }
146
147 if config.TLSKeyFile == "" {
148 logs = append(logs, futureFatal("SCREEGO_TLS_KEY_FILE must be set if TLS is enabled"))
149 }
150 }
151
152 var compiledAllowedOrigins []*regexp.Regexp
153 for _, origin := range config.CorsAllowedOrigins {
154 compiled, err := regexp.Compile(origin)
155 if err != nil {
156 logs = append(logs, futureFatal(fmt.Sprintf("invalid regex: %s", err)))
157 }
158 compiledAllowedOrigins = append(compiledAllowedOrigins, compiled)
159 }

Callers 1

serveCmdFunction · 0.92

Calls 6

parsePortRangeMethod · 0.95
getExecutableOrWorkDirFunction · 0.85
getFilesFunction · 0.85
futureFatalFunction · 0.85
parseIPProviderFunction · 0.85
logDeprecatedFunction · 0.85

Tested by

no test coverage detected