Skip to content

Commit

Permalink
version 0.2.1.1: add NEO4J_BOLT_VERSION (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
maksbotan authored Nov 28, 2023
1 parent 5c8ee8a commit e2c264f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [0.2.1.1] - 2023-08-21
### Added
- `NEO4J_BOLT_VERSION` configuration.

## [0.2.1.0] - 2021-04-24
### Changed
- Added `HasCallStack` to unsafe functions;
Expand Down
2 changes: 1 addition & 1 deletion bcd-config.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: bcd-config
version: 0.2.1.0
version: 0.2.1.1
synopsis: Library to get config.
description: Library to get config to different systems
homepage: https://github.com/biocad/bcd-config#readme
Expand Down
11 changes: 9 additions & 2 deletions src/System/BCD/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,19 @@ loadDotenv = liftIO $ void $ loadFile defaultConfig
class Typeable a => GetEnv a where
getEnv :: (HasCallStack, MonadIO m) => String -> m a
getEnv key = do
valueM <- liftIO $ lookupEnv key
valueM <- getEnvMaybe key
case valueM of
Nothing -> error $ "bcd-config: could not find environment <" <> key <> ">"
Just val -> return val

getEnvMaybe :: (HasCallStack, MonadIO m) => String -> m (Maybe a)
getEnvMaybe key = do
valueM <- liftIO $ lookupEnv key
case valueM of
Nothing -> return Nothing
Just val -> case convertSafe val of
Nothing -> error $ "bcd-config: could not parse environment <" <> key <> "> = <" <> val <> ">" <> " as type " <> show (typeRep @a)
Just a -> return a
Just a -> return $ Just a

convert :: HasCallStack => String -> a
convert = fromJust . convertSafe
Expand Down
3 changes: 3 additions & 0 deletions src/System/BCD/Config/Neo4j.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module System.BCD.Config.Neo4j
, timeout
, rps
, descr
, version
) where

import Control.DeepSeq (NFData)
Expand All @@ -33,6 +34,7 @@ data Neo4jConfig = Neo4jConfig { _host :: String
, _timeout :: Int
, _rps :: Int
, _descr :: String
, _version :: Maybe Int
}
deriving (Show, Read, Eq, Generic)

Expand Down Expand Up @@ -61,4 +63,5 @@ instance FromDotenv Neo4jConfig where
_timeout <- getEnv "NEO4J_TIMEOUT"
_rps <- getEnv "NEO4J_RPS"
_descr <- getEnv "NEO4J_DESCR"
_version <- getEnvMaybe "NEO4J_BOLT_VERSION"
pure Neo4jConfig{..}

0 comments on commit e2c264f

Please sign in to comment.