1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 00:12:29 +03:00

Consolidate configuration options

This commit is contained in:
Timothy Clem 2018-06-11 08:15:02 -07:00
parent 5eeaaabf76
commit 54fe72ad74

View File

@ -18,11 +18,11 @@ data Config
, configHostName :: String -- ^ HostName , configHostName :: String -- ^ HostName
, configProcessID :: ProcessID -- ^ ProcessID , configProcessID :: ProcessID -- ^ ProcessID
, configHaystackURL :: Maybe String , configHaystackURL :: Maybe String
, configStatsAddr :: Addr , configStatsAddr :: StatsAddr
, configLogOptions :: Options , configLogOptions :: Options
} }
data Addr = Addr { addrHost :: String, addrPort :: String } data StatsAddr = StatsAddr { addrHost :: String, addrPort :: String }
defaultConfig :: IO Config defaultConfig :: IO Config
defaultConfig = do defaultConfig = do
@ -52,7 +52,7 @@ defaultStatsClient = defaultConfig >>= statsClientFromConfig
statsClientFromConfig :: Config -> IO StatsClient statsClientFromConfig :: Config -> IO StatsClient
statsClientFromConfig Config{..} = statsClient (addrHost configStatsAddr) (addrPort configStatsAddr) configAppName statsClientFromConfig Config{..} = statsClient (addrHost configStatsAddr) (addrPort configStatsAddr) configAppName
lookupStatsAddr :: IO Addr lookupStatsAddr :: IO StatsAddr
lookupStatsAddr = do lookupStatsAddr = do
addr <- lookupEnv "STATS_ADDR" addr <- lookupEnv "STATS_ADDR"
let (host', port) = parseAddr (fmap ("statsd://" <>) addr) let (host', port) = parseAddr (fmap ("statsd://" <>) addr)
@ -61,7 +61,7 @@ lookupStatsAddr = do
kubesHost <- lookupEnv "DOGSTATSD_HOST" kubesHost <- lookupEnv "DOGSTATSD_HOST"
let host = fromMaybe host' kubesHost let host = fromMaybe host' kubesHost
pure (Addr host port) pure (StatsAddr host port)
where where
defaultHost = "127.0.0.1" defaultHost = "127.0.0.1"
defaultPort = "28125" defaultPort = "28125"