diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2016-12-29 15:20:15 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2017-04-20 15:32:44 +0300 |
commit | 598a03684324eeac37e51f7606f8a27e1e9603e6 (patch) | |
tree | 0ff64573ab6fd9149cc45a928781146a4e1e359b /src/IRE/Config.hs | |
download | ire-598a03684324eeac37e51f7606f8a27e1e9603e6.tar.gz |
Initial release0.0.0
Diffstat (limited to 'src/IRE/Config.hs')
-rw-r--r-- | src/IRE/Config.hs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/IRE/Config.hs b/src/IRE/Config.hs new file mode 100644 index 0000000..c2b90d6 --- /dev/null +++ b/src/IRE/Config.hs @@ -0,0 +1,51 @@ +{-# LANGUAGE OverloadedStrings #-} + +module IRE.Config ( + ConfigFile(..) +, YOLO(..) +, defaultConfig +) where + +import Control.Applicative (empty) +import Data.Aeson (FromJSON, parseJSON) +import Data.Yaml (Value(Object), (.:), (.:?), (.!=)) + + +data ConfigFile = ConfigFile { + cfPort :: Int +, cfSocket :: Maybe FilePath +, cfYOLO :: YOLO +} deriving (Show) + +data YOLO = YOLO { + yoloCfg :: FilePath +, yoloWeights :: FilePath +, yoloNames :: FilePath +} deriving (Show) + + +defaultConfig :: ConfigFile +defaultConfig = ConfigFile { + cfPort = 8080 + , cfSocket = Nothing + , cfYOLO = YOLO { + yoloCfg = "yolo.cfg" + , yoloWeights = "yolo.weights" + , yoloNames = "yolo.names" + } + } + +instance FromJSON ConfigFile where + parseJSON (Object m) = ConfigFile <$> + m .:? "port" .!= cfPort defaultConfig + <*> m .:? "socket" .!= cfSocket defaultConfig + <*> m .:? "yolo" .!= cfYOLO defaultConfig + parseJSON _ = empty + +instance FromJSON YOLO where + parseJSON (Object m) = YOLO <$> + m .: "cfg" + <*> m .: "weights" + <*> m .: "names" + parseJSON _ = empty + |