Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version 0.2.1.1: add NEO4J_BOLT_VERSION #13

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{..}