{-# LANGUAGE DeriveGeneric #-}
module Instana.SDK.Internal.URL
( URL
, mkHttp
, mkHttps
, mkUrl
) where
import GHC.Generics
data Protocol = HTTP | HTTPS
deriving (Protocol -> Protocol -> Bool
(Protocol -> Protocol -> Bool)
-> (Protocol -> Protocol -> Bool) -> Eq Protocol
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Protocol -> Protocol -> Bool
$c/= :: Protocol -> Protocol -> Bool
== :: Protocol -> Protocol -> Bool
$c== :: Protocol -> Protocol -> Bool
Eq, (forall x. Protocol -> Rep Protocol x)
-> (forall x. Rep Protocol x -> Protocol) -> Generic Protocol
forall x. Rep Protocol x -> Protocol
forall x. Protocol -> Rep Protocol x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Protocol x -> Protocol
$cfrom :: forall x. Protocol -> Rep Protocol x
Generic)
instance Show Protocol where
show :: Protocol -> String
show HTTP = "http://"
show HTTPS = "https://"
data URL = URL
{ URL -> Protocol
protocol :: Protocol
, URL -> String
host :: String
, URL -> Int
port :: Int
, URL -> String
path :: String
} deriving (URL -> URL -> Bool
(URL -> URL -> Bool) -> (URL -> URL -> Bool) -> Eq URL
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: URL -> URL -> Bool
$c/= :: URL -> URL -> Bool
== :: URL -> URL -> Bool
$c== :: URL -> URL -> Bool
Eq, (forall x. URL -> Rep URL x)
-> (forall x. Rep URL x -> URL) -> Generic URL
forall x. Rep URL x -> URL
forall x. URL -> Rep URL x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep URL x -> URL
$cfrom :: forall x. URL -> Rep URL x
Generic)
instance Show URL where
show :: URL -> String
show url :: URL
url =
(Protocol -> String
forall a. Show a => a -> String
show (Protocol -> String) -> Protocol -> String
forall a b. (a -> b) -> a -> b
$ URL -> Protocol
protocol URL
url) String -> ShowS
forall a. [a] -> [a] -> [a]
++
(URL -> String
host URL
url) String -> ShowS
forall a. [a] -> [a] -> [a]
++ ":" String -> ShowS
forall a. [a] -> [a] -> [a]
++
(Int -> String
forall a. Show a => a -> String
show (Int -> String) -> Int -> String
forall a b. (a -> b) -> a -> b
$ URL -> Int
port URL
url) String -> ShowS
forall a. [a] -> [a] -> [a]
++ "/" String -> ShowS
forall a. [a] -> [a] -> [a]
++
(URL -> String
path URL
url)
mkUrl ::
Protocol
-> String
-> Int
-> String
-> URL
mkUrl :: Protocol -> String -> Int -> String -> URL
mkUrl _protocol :: Protocol
_protocol _host :: String
_host _port :: Int
_port _path :: String
_path =
URL :: Protocol -> String -> Int -> String -> URL
URL
{ protocol :: Protocol
protocol = Protocol
_protocol
, host :: String
host = String
_host
, port :: Int
port = Int
_port
, path :: String
path = String
_path
}
mkHttp ::
String
-> Int
-> String
-> URL
mkHttp :: String -> Int -> String -> URL
mkHttp = Protocol -> String -> Int -> String -> URL
mkUrl Protocol
HTTP
mkHttps ::
String
-> Int
-> String
-> URL
mkHttps :: String -> Int -> String -> URL
mkHttps = Protocol -> String -> Int -> String -> URL
mkUrl Protocol
HTTPS