-- 1. DATA DEFINITIONS (These must be exported)
data ConfigEntry = ConfigEntry
{ name :: Text
, nameserver :: Text
, domain :: Text
, raw_mode :: Text
, port :: Maybe Int
, speeder_password :: Text
, udp2raw_password :: Text
}
type Config = [ConfigEntry]
parseJSON = withObject "ConfigEntry" $ \v -> ConfigEntry
<$> v .: "name"
<*> v .: "nameserver"
<*> v .: "domain"
<*> v .: "raw_mode"
<*> v .:? "port"
<*> v .: "speeder_password"
<*> v .: "udp2raw_password"
-- 2. EXPORTED FUNCTION
-- This function reads the file and returns the parsed configuration or an error message.
do
result <- decodeFileEither configFile
case result of
Left err -> pure $ Left $ "Error parsing YAML from " ++ configFile ++ ": " ++ show err
Right cfg -> pure $ Right cfg