Skip to content

Instantly share code, notes, and snippets.

@seanhess
Last active August 29, 2015 14:20
Show Gist options
  • Save seanhess/8ef526da5359ae3ffdf5 to your computer and use it in GitHub Desktop.
Save seanhess/8ef526da5359ae3ffdf5 to your computer and use it in GitHub Desktop.
GetText
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.
{-# 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