Skip to content
Snippets Groups Projects
Verified Commit 04d71178 authored by jan.hamal.dvorak's avatar jan.hamal.dvorak
Browse files

Add shortcuts to read Config outside of Action

parent 731efa00
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,10 @@ module Hikaru.Config ...@@ -26,6 +26,10 @@ module Hikaru.Config
, configFromFile , configFromFile
, configDefault , configDefault
-- * Reading Config
, configGetMaybe
, configGetDefault
-- * Secrets -- * Secrets
, generateSecret , generateSecret
) )
...@@ -38,6 +42,7 @@ where ...@@ -38,6 +42,7 @@ where
import Data.ByteArray.Encoding import Data.ByteArray.Encoding
import Data.String.Conversions import Data.String.Conversions
import Data.Text hiding (map) import Data.Text hiding (map)
import Hikaru.Types
import System.Environment import System.Environment
...@@ -102,6 +107,20 @@ where ...@@ -102,6 +107,20 @@ where
] ]
-- |
-- Try to obtain value of a configuration key.
--
configGetMaybe :: (Param a) => Text -> Config -> Maybe a
configGetMaybe name cfg = fromParam =<< Map.lookup name cfg
-- |
-- Obtain value of a configuration key or the provided default.
--
configGetDefault :: (Param a) => Text -> a -> Config -> a
configGetDefault name value = fromMaybe value . configGetMaybe name
-- | -- |
-- Generate a random base64-encoded secret of given length -- Generate a random base64-encoded secret of given length
-- (in decoded bytes). -- (in decoded bytes).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment