From 6d6c997df576b458d31d7d432f77f51c3efa9b85 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Wed, 13 Nov 2024 21:57:57 +0000 Subject: [PATCH] working on documentation --- haskell/lib/API.hs | 19 ++++++++++++++++--- haskell/lib/CLI.hs | 11 ++++++++--- haskell/lib/Environment.hs | 5 ++++- haskell/lib/Error.hs | 21 ++++++++++++++++----- haskell/lib/P2PRC.hs | 16 +++++++++++----- 5 files changed, 55 insertions(+), 17 deletions(-) diff --git a/haskell/lib/API.hs b/haskell/lib/API.hs index 361c519..444ab2f 100644 --- a/haskell/lib/API.hs +++ b/haskell/lib/API.hs @@ -10,7 +10,9 @@ import System.Process ( ProcessHandle ) import Data.Aeson ( FromJSON ) -import Error (IOEitherError) +import Error + ( IOEitherError + ) import JSON ( IPAdressTable @@ -40,8 +42,19 @@ data P2PRCapi = MkP2PRCapi } -data MapPortRequest - = MkMapPortRequest Int String +{- | + +__Example:__ + +@ +port = 'MkMapPortRequest' 8080 \"jose.akilan.io\" +@ + +-} +data MapPortRequest = + MkMapPortRequest + Int -- ^ TCP socket number + String -- ^ Network domain name getP2prcAPI :: IOEitherError P2PRCapi diff --git a/haskell/lib/CLI.hs b/haskell/lib/CLI.hs index 1750df9..fba2cf7 100644 --- a/haskell/lib/CLI.hs +++ b/haskell/lib/CLI.hs @@ -8,9 +8,9 @@ import System.Process , ProcessHandle ) -import System.Exit ( ExitCode(ExitFailure) ) - -import Data.Aeson +import System.Exit + ( ExitCode(ExitFailure) + ) import Error ( IOEitherError @@ -18,6 +18,11 @@ import Error , assignError ) +import Data.Aeson + ( FromJSON + , eitherDecode + ) + import qualified Data.Text as T import qualified Data.ByteString.Lazy.Char8 as LBC8 diff --git a/haskell/lib/Environment.hs b/haskell/lib/Environment.hs index 0eca44e..88edd1b 100644 --- a/haskell/lib/Environment.hs +++ b/haskell/lib/Environment.hs @@ -1,4 +1,7 @@ -module Environment ( cleanEnvironment ) where +module Environment + ( cleanEnvironment + ) + where import System.Directory diff --git a/haskell/lib/Error.hs b/haskell/lib/Error.hs index ad4fd9c..6cae2d3 100644 --- a/haskell/lib/Error.hs +++ b/haskell/lib/Error.hs @@ -1,13 +1,24 @@ -module Error where +module Error + ( Error(..) + , IOEitherError + , assignError + ) where +-- ^ Error type for the application data Error - = MkUnknownError String - | MkErrorSpawningProcess String - | MkSystemError Int String String + = MkUnknownError + String -- ^ error message + | MkErrorSpawningProcess + String -- ^ error message + | MkSystemError + Int -- ^ System error code + String -- ^ String1 + String -- ^ String2 deriving Show -type IOEitherError a = IO (Either Error a) +-- ^ Type synonym for an IO action with either returns an Error or a parsed value +type IOEitherError a = IO ( Either Error a) assignError :: String -> Error assignError = MkUnknownError diff --git a/haskell/lib/P2PRC.hs b/haskell/lib/P2PRC.hs index f502f47..fc5096d 100644 --- a/haskell/lib/P2PRC.hs +++ b/haskell/lib/P2PRC.hs @@ -12,7 +12,7 @@ This helper module exports the main functions and data type definitions necessary to get started with the P2PRC api. -A minimal application will require the import of "runP2PRC" function that accepts a "MapPortRequest" value that exposes a specific port number and associates it with a domain name in the internet. +A minimal application will require the import of 'runP2PRC' function that accepts a 'MapPortRequest' value that exposes a specific port number and associates it with a domain name in the internet. This is a small template to get quickly get started with this interface. We assume the user has already an application listening on the tcp socket "8080". @@ -35,14 +35,15 @@ This is a small template to get quickly get started with this interface. We assu module P2PRC - ( MapPortRequest(..) + ( getP2prcAPI + , runP2PRC + , MapPortRequest(..) , P2PRCapi , IPAdressTable , MapPortResponse , P2prcConfig + , Error , IOEitherError - , getP2prcAPI - , runP2PRC ) where @@ -64,4 +65,9 @@ import API ) -import Error (IOEitherError) +import Error + ( Error + , IOEitherError + ) + +