MCPcopy Index your code
hub / github.com/SpectoLabs/hoverfly / InitSettings

Function InitSettings

core/settings.go:127–212  ·  view source on GitHub ↗

InitSettings gets and returns initial configuration from env variables or sets defaults

()

Source from the content-addressed store, hash-verified

125// InitSettings gets and returns initial configuration from env
126// variables or sets defaults
127func InitSettings() *Configuration {
128
129 var appConfig Configuration
130 // getting default admin interface port
131 if os.Getenv(HoverflyAdminPortEV) != "" {
132 appConfig.AdminPort = os.Getenv(HoverflyAdminPortEV)
133 } else {
134 appConfig.AdminPort = DefaultAdminPort
135 }
136
137 // getting proxy port
138 if os.Getenv(HoverflyProxyPortEV) != "" {
139 appConfig.ProxyPort = os.Getenv(HoverflyProxyPortEV)
140 } else {
141 appConfig.ProxyPort = DefaultPort
142 }
143
144 appConfig.ListenOnHost = DefaultListenOnHost
145
146 // getting external proxy
147 if os.Getenv(HoverflyUpstreamProxyPortEV) != "" {
148 appConfig.UpstreamProxy = os.Getenv(HoverflyUpstreamProxyPortEV)
149 } else {
150 appConfig.UpstreamProxy = ""
151 }
152
153 databasePath := os.Getenv(HoverflyDBEV)
154 if databasePath == "" {
155 appConfig.DatabasePath = DefaultDatabasePath
156 }
157
158 appConfig.Webserver = false
159
160 if os.Getenv(HoverflySecretEV) != "" {
161 appConfig.SecretKey = []byte(os.Getenv(HoverflySecretEV))
162 } else {
163 appConfig.SecretKey = getRandomName(10)
164 }
165
166 if os.Getenv(HoverflyTokenExpirationEV) != "" {
167
168 exp, err := strconv.Atoi(os.Getenv(HoverflyTokenExpirationEV))
169 if err != nil {
170 log.WithFields(log.Fields{
171 "error": err.Error(),
172 "HoverflyTokenExpiration": os.Getenv(HoverflyTokenExpirationEV),
173 }).Fatal("failed to get token exipration delta, using default value")
174 exp = DefaultJWTExpirationDelta
175 }
176 appConfig.JWTExpirationDelta = exp
177
178 } else {
179 appConfig.JWTExpirationDelta = DefaultJWTExpirationDelta
180 }
181
182 if os.Getenv(HoverflyAuthEnabledEV) == "true" {
183 appConfig.AuthEnabled = true
184 } else {

Calls 3

ConvertToNewMiddlewareFunction · 0.92
getRandomNameFunction · 0.85
ErrorMethod · 0.45