Last active
August 29, 2015 14:20
-
-
Save seanhess/8ef526da5359ae3ffdf5 to your computer and use it in GitHub Desktop.
GetText
This file contains hidden or 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
server/Serials/Admin.hs:45:25: | |
Couldn't match expected type ‘EitherT | |
(Int, a0) IO Data.ByteString.Lazy.Internal.ByteString’ | |
with actual type ‘Server GetText’ | |
The type variable ‘a0’ is ambiguous | |
In the first argument of ‘runEitherT’, namely ‘action’ | |
In a stmt of a 'do' block: e <- runEitherT action | |
Failed, modules loaded: Serials.Link, Serials.Model.Crud, Serials.Model.Scan, Serials.Link.Import, Serials.Link.Scrape, Serials.Link.Parse, Serials.Link.Link, Serials.Model.App. |
This file contains hidden or 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
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE TypeFamilies #-} | |
module Serials.Admin where | |
import Data.Text (Text) | |
import Control.Monad.Trans.Either | |
import Data.Aeson | |
import Data.Proxy | |
import Data.String.Conversions | |
import Data.Typeable | |
import Network.HTTP.Types | |
import Network.Wai | |
import Servant.Server | |
import Servant.Server.Internal | |
-- Copied from: http://haskell-servant.github.io/servant-server/src/Servant-Server-Internal.html#Server | |
data GetText = GetText Text deriving (Typeable) | |
type instance Server GetText = EitherT (Int, String) IO Text | |
instance HasServer GetText where | |
route Proxy action request respond | |
| null (pathInfo request) && requestMethod request == methodGet = do | |
e <- runEitherT action | |
respond . succeedWith $ case e of | |
Right output -> | |
responseLBS ok200 [("Content-Type", "text/plain")] output | |
Left (status, message) -> | |
responseLBS (mkStatus status (cs message)) [] (cs message) | |
| null (pathInfo request) && requestMethod request /= methodGet = | |
respond $ failWith WrongMethod | |
| otherwise = respond $ failWith NotFound |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment