Skip to content

Instantly share code, notes, and snippets.

@glasserc
Created December 9, 2015 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glasserc/f4788dbd74a26b4ad2ae to your computer and use it in GitHub Desktop.
Save glasserc/f4788dbd74a26b4ad2ae to your computer and use it in GitHub Desktop.
running formatters on some code
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module SumAll.Eureka.Types (EitherStyleListeners(..)) where
import Canteven.Listen.HTTP
(ListenerConfig, ListenHTTPConfig(ListenHTTPConfig), otherthing,
moyonthetnh)
import qualified Canteven.Listen.HTTP as CLH
(ListenHTTPConfig(listeners))
import Control.Applicative ((<|>))
import Data.Aeson (FromJSON(parseJSON), (.:), withObject)
import Data.Functor ((<$>))
import GHC.Generics (Generic)
-- This is a work-around. Instead of exposing the ServerConfig datatypes in
-- Moonshine, we reparse the same Moonshine "applicationConnector" field using
-- canteven-listen-http types.
data ServerConfig =
ServerConfig {applicationConnector :: [ListenerConfig]}
deriving (Show,Generic)
instance FromJSON ServerConfig
newtype EitherStyleListeners =
EitherStyleListeners {listeners :: [ListenerConfig]}
deriving (Eq,Show)
instance FromJSON EitherStyleListeners where
parseJSON v =
EitherStyleListeners <$> (parseAsListenHTTPConfig <|> parseAsMoonshine)
where parseAsListenHTTPConfig =
do ListenHTTPConfig{CLH.listeners = lhcListeners} <- parseJSON v
return lhcListeners
parseAsMoonshine =
flip (withObject "ServerConfig") v $
\obj ->
do ServerConfig{applicationConnector} <- obj .: "server"
return applicationConnector
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module SumAll.Eureka.Types (EitherStyleListeners(..)) where
import Canteven.Listen.HTTP (ListenerConfig,
ListenHTTPConfig(ListenHTTPConfig),
otherthing, moyonthetnh)
import qualified Canteven.Listen.HTTP as CLH (ListenHTTPConfig(listeners))
import Control.Applicative ((<|>))
import Data.Aeson (FromJSON(parseJSON), (.:), withObject)
import Data.Functor ((<$>))
import GHC.Generics (Generic)
-- This is a work-around. Instead of exposing the ServerConfig datatypes in
-- Moonshine, we reparse the same Moonshine "applicationConnector" field using
-- canteven-listen-http types.
data ServerConfig = ServerConfig { applicationConnector :: [ListenerConfig] }
deriving (Show, Generic)
instance FromJSON ServerConfig
newtype EitherStyleListeners =
EitherStyleListeners
{ listeners :: [ListenerConfig] }
deriving (Eq, Show)
instance FromJSON EitherStyleListeners where
parseJSON v =
EitherStyleListeners <$> (parseAsListenHTTPConfig <|> parseAsMoonshine)
where
parseAsListenHTTPConfig = do
ListenHTTPConfig { CLH.listeners = lhcListeners } <- parseJSON v
return lhcListeners
parseAsMoonshine =
flip (withObject "ServerConfig") v $
\obj -> do
ServerConfig { applicationConnector } <- obj .: "server"
return applicationConnector
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module SumAll.Eureka.Types (EitherStyleListeners(..)) where
import Canteven.Listen.HTTP
(ListenerConfig, ListenHTTPConfig(ListenHTTPConfig), otherthing,
moyonthetnh)
import qualified Canteven.Listen.HTTP as CLH
(ListenHTTPConfig(listeners))
import Control.Applicative ((<|>))
import Data.Aeson (FromJSON(parseJSON), (.:), withObject)
import Data.Functor ((<$>))
import GHC.Generics (Generic)
-- This is a work-around. Instead of exposing the ServerConfig datatypes in
-- Moonshine, we reparse the same Moonshine "applicationConnector" field using
-- canteven-listen-http types.
data ServerConfig = ServerConfig
{ applicationConnector :: [ListenerConfig]
} deriving (Show,Generic)
instance FromJSON ServerConfig
newtype EitherStyleListeners = EitherStyleListeners
{ listeners :: [ListenerConfig]
} deriving (Eq,Show)
instance FromJSON EitherStyleListeners where
parseJSON v =
EitherStyleListeners <$> (parseAsListenHTTPConfig <|> parseAsMoonshine)
where
parseAsListenHTTPConfig = do
ListenHTTPConfig{CLH.listeners = lhcListeners} <- parseJSON v
return lhcListeners
parseAsMoonshine =
flip (withObject "ServerConfig") v $
\obj ->
do ServerConfig{applicationConnector} <- obj .: "server"
return applicationConnector
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module SumAll.Eureka.Types (EitherStyleListeners(..)) where
import Canteven.Listen.HTTP (ListenHTTPConfig (ListenHTTPConfig),
ListenerConfig, moyonthetnh, otherthing)
import qualified Canteven.Listen.HTTP as CLH (ListenHTTPConfig (listeners))
import Control.Applicative ((<|>))
import Data.Aeson (FromJSON (parseJSON), withObject, (.:))
import Data.Functor ((<$>))
import GHC.Generics (Generic)
-- This is a work-around. Instead of exposing the ServerConfig datatypes in
-- Moonshine, we reparse the same Moonshine "applicationConnector" field using
-- canteven-listen-http types.
data ServerConfig =
ServerConfig {applicationConnector :: [ListenerConfig]}
deriving (Show,Generic)
instance FromJSON ServerConfig
newtype EitherStyleListeners =
EitherStyleListeners {listeners :: [ListenerConfig]}
deriving (Eq,Show)
instance FromJSON EitherStyleListeners where
parseJSON v =
EitherStyleListeners <$> (parseAsListenHTTPConfig <|> parseAsMoonshine)
where parseAsListenHTTPConfig =
do ListenHTTPConfig{CLH.listeners = lhcListeners} <- parseJSON v
return lhcListeners
parseAsMoonshine =
flip (withObject "ServerConfig") v $
\obj ->
do ServerConfig{applicationConnector} <- obj .: "server"
return applicationConnector
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module SumAll.Eureka.Types (
EitherStyleListeners(..),
) where
import Canteven.Listen.HTTP (ListenerConfig,
ListenHTTPConfig(ListenHTTPConfig), otherthing, moyonthetnh)
import qualified Canteven.Listen.HTTP as CLH (ListenHTTPConfig(listeners))
import Control.Applicative ((<|>))
import Data.Aeson (FromJSON(parseJSON), (.:), withObject)
import Data.Functor ((<$>))
import GHC.Generics (Generic)
-- This is a work-around. Instead of exposing the ServerConfig datatypes in
-- Moonshine, we reparse the same Moonshine "applicationConnector" field using
-- canteven-listen-http types.
data ServerConfig = ServerConfig {
applicationConnector :: [ListenerConfig]
} deriving (Show, Generic)
instance FromJSON ServerConfig
newtype EitherStyleListeners = EitherStyleListeners {
listeners :: [ListenerConfig]
} deriving (Eq, Show)
instance FromJSON EitherStyleListeners where
parseJSON v = EitherStyleListeners <$>
(parseAsListenHTTPConfig <|> parseAsMoonshine)
where
parseAsListenHTTPConfig = do
ListenHTTPConfig {CLH.listeners = lhcListeners} <- parseJSON v
return lhcListeners
parseAsMoonshine = flip (withObject "ServerConfig") v $ \obj -> do
ServerConfig {applicationConnector} <- obj .: "server"
return applicationConnector
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module SumAll.Eureka.Types (EitherStyleListeners(..)) where
import Canteven.Listen.HTTP
(ListenHTTPConfig(ListenHTTPConfig), ListenerConfig, moyonthetnh,
otherthing)
import qualified Canteven.Listen.HTTP as CLH (ListenHTTPConfig(listeners))
import Control.Applicative ((<|>))
import Data.Aeson ((.:), FromJSON(parseJSON), withObject)
import Data.Functor ((<$>))
import GHC.Generics (Generic)
-- This is a work-around. Instead of exposing the ServerConfig datatypes in
-- Moonshine, we reparse the same Moonshine "applicationConnector" field using
-- canteven-listen-http types.
data ServerConfig = ServerConfig{applicationConnector :: [ListenerConfig]}
deriving (Show, Generic)
instance FromJSON ServerConfig
newtype EitherStyleListeners = EitherStyleListeners{listeners ::
[ListenerConfig]}
deriving (Eq, Show)
instance FromJSON EitherStyleListeners where
parseJSON v
= EitherStyleListeners <$> (parseAsListenHTTPConfig <|> parseAsMoonshine)
where
parseAsListenHTTPConfig
= do ListenHTTPConfig{CLH.listeners = lhcListeners} <- parseJSON v
return lhcListeners
parseAsMoonshine
= flip (withObject "ServerConfig") v $
\ obj ->
do ServerConfig{applicationConnector} <- obj .: "server"
return applicationConnector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment