1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE PolyKinds #-}
5{-# LANGUAGE TypeFamilies #-}
6{-# LANGUAGE TypeOperators #-}
8import Control.Monad.IO.Class (liftIO)
11import Data.Char (toUpper)
12import qualified Data.List as L
15import Data.Text hiding (head, length, map,
17import qualified Data.Text as T
18import qualified Data.Text.IO as T
20import Servant.Server.Internal.SnapShims
22import Snap.Http.Server
26-- import Snap.Util.FileServe
32-- | A greet message data type
33newtype Greet = Greet { _msg :: Text }
34 deriving (Generic, Show)
36instance FromJSON Greet
44-- Server-side handlers.
46-- There's one handler per endpoint, which, just like in the type
47-- that represents the API, are glued together using :<|>.
49-- Each handler runs in the 'ExceptT ServantErr IO' monad.
50server :: Server API (Handler App App)
51server = return () :<|> return 100 :<|> sayhi :<|> dbl :<|> multi :<|> qna :<|> serveDirectory "static"
52 where sayhi :: Maybe Text -> [Text] -> Bool -> Handler App App Text
53 sayhi nm greetings withGusto = case nm of
54 Nothing -> return ("Sorry, who are you?" :: Text)
56 let modifier = bool id T.toUpper withGusto
58 | null greetings = "Hi, "
59 | length greetings == 1 = L.head greetings <> ", "
60 | otherwise = T.intercalate ", " (L.init greetings)
61 <> ", and " <> L.last greetings <> ", "
62 return . modifier $ greetPart <> n
63 dbl x = if x `elem` [4,13]
64 then throwError $ err500 { errBody = "No unlucky numbers please" }
66 multi = return . bool "Box unchecked" "Box Checked"
69 putStrLn $ "qna got: " ++ show q
70 T.putStrLn $ unQuestion q
71 return $ Answer $ unQuestion q
73-- Turn the server into a WAI app. 'serve' is provided by servant,
74-- more precisely by the Servant.Server module.
75test :: Handler App App ()
76test = serveSnap testApi server
78initApp :: SnapletInit App App
79initApp = makeSnaplet "myapp" "example" Nothing $ do
81 ,("", serveDirectory "static")
85-- Put this all to work!
87main = serveSnaplet mempty initApp
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list