-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
version 0.1.1.0: lens, json instances (#7)
- Loading branch information
1 parent
b150c9b
commit 689584b
Showing
11 changed files
with
161 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module System.BCD.Config | ||
( FromJsonConfig (..) | ||
( | ||
FromJsonConfig (..) | ||
, getConfigText | ||
) where | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,38 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module System.BCD.Config.Mysql | ||
( MysqlConfig (..) | ||
( | ||
MysqlConfig (..) | ||
, FromJsonConfig (..) | ||
, host | ||
, port | ||
, user | ||
, password | ||
, descr | ||
) where | ||
|
||
import Data.Aeson.Picker ((|--)) | ||
import System.BCD.Config (FromJsonConfig (..), getConfigText) | ||
import Control.Lens (makeLenses) | ||
import Data.Aeson (FromJSON (..), ToJSON (..), | ||
genericParseJSON, genericToJSON) | ||
import Data.Aeson.Casing (aesonDrop, snakeCase) | ||
import Data.Aeson.Picker ((|--)) | ||
import GHC.Generics (Generic) | ||
import System.BCD.Config (FromJsonConfig (..), getConfigText) | ||
|
||
data MysqlConfig = MysqlConfig { _host :: String | ||
, _port :: Int | ||
, _user :: String | ||
, _password :: String | ||
, _descr :: String | ||
} | ||
deriving (Show, Read, Eq) | ||
deriving (Show, Read, Eq, Generic) | ||
|
||
makeLenses ''MysqlConfig | ||
|
||
instance ToJSON MysqlConfig where | ||
toJSON = genericToJSON $ aesonDrop 1 snakeCase | ||
instance FromJSON MysqlConfig where | ||
parseJSON = genericParseJSON $ aesonDrop 1 snakeCase | ||
|
||
instance FromJsonConfig MysqlConfig where | ||
fromJsonConfig = do | ||
jsonText <- getConfigText | ||
let get field = jsonText |-- ["deploy", "mysql", field] | ||
pure $ MysqlConfig (get "host") | ||
(get "port") | ||
(get "user") | ||
(get "password") | ||
(get "descr") | ||
config <- getConfigText | ||
pure $ config |-- ["deploy", "mysql"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,36 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module System.BCD.Config.Schrodinger | ||
( SchrodingerConfig (..) | ||
( | ||
SchrodingerConfig (..) | ||
, FromJsonConfig (..) | ||
, host | ||
, port | ||
, user | ||
, password | ||
) where | ||
|
||
import Control.Lens (makeLenses) | ||
import Data.Aeson (FromJSON (..), ToJSON (..), | ||
genericParseJSON, genericToJSON) | ||
import Data.Aeson.Casing (aesonDrop, snakeCase) | ||
import Data.Aeson.Picker ((|--)) | ||
import GHC.Generics (Generic) | ||
import System.BCD.Config (FromJsonConfig (..), getConfigText) | ||
|
||
data SchrodingerConfig = SchrodingerConfig { _host :: String | ||
, _port :: Int | ||
, _user :: String | ||
, _password :: String | ||
} | ||
deriving (Show, Read, Eq) | ||
deriving (Show, Read, Eq, Generic) | ||
|
||
makeLenses ''SchrodingerConfig | ||
|
||
instance ToJSON SchrodingerConfig where | ||
toJSON = genericToJSON $ aesonDrop 1 snakeCase | ||
instance FromJSON SchrodingerConfig where | ||
parseJSON = genericParseJSON $ aesonDrop 1 snakeCase | ||
|
||
instance FromJsonConfig SchrodingerConfig where | ||
fromJsonConfig = do | ||
jsonText <- getConfigText | ||
let get field = jsonText |-- ["deploy", "schrodinger", field] | ||
pure $ SchrodingerConfig (get "host") | ||
(get "port") | ||
(get "user") | ||
(get "password") | ||
config <- getConfigText | ||
pure $ config |-- ["deploy", "schrodinger"] |