-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0aca913
commit d4fabcd
Showing
9 changed files
with
185 additions
and
73 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{-# LANGUAGE RecordWildCards #-} | ||
-- | Different funtions to make life easier. | ||
module Parsing | ||
( parseAddress | ||
) where | ||
|
||
|
||
import Data.ByteString (ByteString) | ||
import Data.Text (Text) | ||
import Network.HTTP.Client (isIpAddress) | ||
|
||
import qualified Data.Text.Encoding as T | ||
|
||
import PrettyPrint | ||
import Status (ServerAdress(..)) | ||
|
||
data ParsingError | ||
= AdressParsingError | ||
{ parsedText :: Text | ||
, errorMessage :: Text | ||
} | ||
-- | WhateverParsingError | ||
deriving (Show) | ||
|
||
instance PrettyPrint ParsingError where | ||
prettyPrint AdressParsingError{..} = errorMessage | ||
|
||
|
||
parseAddress | ||
:: Text | ||
-> Either ParsingError ServerAdress | ||
parseAddress text = | ||
let adress = T.encodeUtf8 text | ||
in if isIpAddress adress | ||
then Right $ makeHttpAdress adress | ||
else Left $ AdressParsingError text | ||
$ "\"" <> text <> "\" is not a valid IP address." | ||
|
||
makeHttpAdress :: ByteString -> ServerAdress | ||
makeHttpAdress host = | ||
ServerAdress {_host = host, _port = 80} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{-# LANGUAGE DefaultSignatures #-} | ||
-- | Printing data for humans. | ||
module PrettyPrint | ||
( PrettyPrint(..) | ||
) where | ||
|
||
import Data.Text (Text, pack) | ||
|
||
class PrettyPrint a where | ||
prettyPrint :: a -> Text | ||
default prettyPrint :: Show a => a -> Text | ||
prettyPrint = pack . show |
This file contains 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
This file contains 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