mirror of
https://github.com/openfaas/faas.git
synced 2025-06-22 14:53:25 +00:00
Add GatewayConfig
Add env configurable readTimeout / writeTimeout Add env-timeout test Modify appropriate Dockerfiles Signed-off-by: leigh schrandt <leigh@null.net>
This commit is contained in:
committed by
Alex Ellis
parent
a9774a9c2a
commit
457d0be78b
61
gateway/readconfig.go
Normal file
61
gateway/readconfig.go
Normal file
@ -0,0 +1,61 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// OsEnv implements interface to wrap os.Getenv
|
||||
type OsEnv struct {
|
||||
}
|
||||
|
||||
// Getenv wraps os.Getenv
|
||||
func (OsEnv) Getenv(key string) string {
|
||||
return os.Getenv(key)
|
||||
}
|
||||
|
||||
// HasEnv provides interface for os.Getenv
|
||||
type HasEnv interface {
|
||||
Getenv(key string) string
|
||||
}
|
||||
|
||||
// ReadConfig constitutes config from env variables
|
||||
type ReadConfig struct {
|
||||
}
|
||||
|
||||
func parseBoolValue(val string) bool {
|
||||
if val == "true" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func parseIntValue(val string, fallback int) int {
|
||||
if len(val) > 0 {
|
||||
parsedVal, parseErr := strconv.Atoi(val)
|
||||
if parseErr == nil && parsedVal >= 0 {
|
||||
return parsedVal
|
||||
}
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
// Read fetches config from environmental variables.
|
||||
func (ReadConfig) Read(hasEnv HasEnv) GatewayConfig {
|
||||
cfg := GatewayConfig{}
|
||||
|
||||
readTimeout := parseIntValue(hasEnv.Getenv("read_timeout"), 8)
|
||||
writeTimeout := parseIntValue(hasEnv.Getenv("write_timeout"), 8)
|
||||
|
||||
cfg.readTimeout = time.Duration(readTimeout) * time.Second
|
||||
cfg.writeTimeout = time.Duration(writeTimeout) * time.Second
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
// GatewayConfig for the process.
|
||||
type GatewayConfig struct {
|
||||
readTimeout time.Duration
|
||||
writeTimeout time.Duration
|
||||
}
|
Reference in New Issue
Block a user