Remove redundant entry point; adjust comments in main init; update init function names from 'main'

This commit is contained in:
James Eversole 2024-02-24 13:07:33 -06:00
parent 19c6801d12
commit 3863ddf42e
5 changed files with 15 additions and 23 deletions

View File

@ -16,8 +16,7 @@ extra-source-files:
executable Purr executable Purr
main-is: Main.hs main-is: Main.hs
hs-source-dirs: hs-source-dirs:
app src
, src
default-extensions: default-extensions:
ConstraintKinds ConstraintKinds
DeriveGeneric DeriveGeneric
@ -64,5 +63,4 @@ executable Purr
Feature.Sharing.HTTP Feature.Sharing.HTTP
Feature.Sharing.SQLite Feature.Sharing.SQLite
Feature.Sharing.Templates Feature.Sharing.Templates
Lib
default-language: Haskell2010 default-language: Haskell2010

View File

@ -1,7 +0,0 @@
module Main where
import Prelude
import qualified Lib
main :: IO ()
main = Lib.main

View File

@ -1,21 +1,22 @@
module Core.Configuration ( adminEmail, appPort module Core.Configuration ( adminEmail, appPort
, confLinkLength, dataPath, dbPath , confLinkLength, dataPath, dbPath
, encKey, getRuntimeEnvironment , encKey, getRuntimeEnvironment
, keyFileInit, main) where , keyFileInit, init) where
import qualified Data.ByteString as B import qualified Data.ByteString as B
import Control.Monad (mapM) import Control.Monad (mapM)
import Configuration.Dotenv
import Core.Types import Core.Types
import Crypto.Saltine.Core.SecretBox (newKey) import Crypto.Saltine.Core.SecretBox (newKey)
import Crypto.Saltine.Class (encode) import Crypto.Saltine.Class (encode)
import Configuration.Dotenv import Prelude hiding (init)
import System.Directory (doesFileExist) import System.Directory (doesFileExist)
import System.Environment (getEnv, lookupEnv) import System.Environment (getEnv, lookupEnv)
-- Load environment variables from dotenv file if required -- Load environment variables from dotenv file if required
main :: IO () init :: IO ()
main = do init = do
reqEnvLookup <- getRequiredEnv reqEnvLookup <- getRequiredEnv
if (Nothing `elem` reqEnvLookup) if (Nothing `elem` reqEnvLookup)
then checkEnvFile requiredEnvVars then checkEnvFile requiredEnvVars

View File

@ -6,12 +6,13 @@ import Core.Types
import Data.ByteString as B import Data.ByteString as B
import Database.SQLite.Simple import Database.SQLite.Simple
import Database.SQLite.Simple.FromRow import Database.SQLite.Simple.FromRow
import Prelude hiding (init)
import qualified Data.Text as T import qualified Data.Text as T
-- Set up SQLite database table when Purr starts if it doesn't already exist -- Set up SQLite database table when Purr starts if it doesn't already exist
main :: IO () init :: IO ()
main = do init = do
conn <- open dbPath conn <- open dbPath
execute_ conn execute_ conn
"CREATE TABLE IF NOT EXISTS pws\ "CREATE TABLE IF NOT EXISTS pws\

View File

@ -1,4 +1,4 @@
module Lib ( main ) where module Main ( main ) where
import qualified Core.Configuration as Configuration import qualified Core.Configuration as Configuration
import qualified Core.HTTP as HTTP import qualified Core.HTTP as HTTP
@ -16,17 +16,16 @@ main = do
-- Initialize the RNG used for sodium encryption (Saltine library) -- Initialize the RNG used for sodium encryption (Saltine library)
sodiumInit sodiumInit
{- Initialize our dotenv configuration which reads from a .env configuration {- Initialize our dotenv configuration which reads from a .env configuration
file unless the PURRNOFILE env var exists already. -} if any required variables are missing from the provided environment -}
Configuration.main Configuration.init
{- Initialize the encryption key file if it doesn't {- Initialize the encryption key file if it doesn't
exist yet or use the existing key -} exist yet or use the existing key -}
Configuration.keyFileInit Configuration.keyFileInit
{- Initialize our database by ensuring the SQLite file exists {- Initialize our database by ensuring the SQLite file exists
and has tables setup as the application expects -} and has tables setup as the application expects -}
DB.main DB.init
{- Get the configured port to run on and start the Scotty webserver app {- Get the configured port to run on and start the Scotty webserver app
defined in HTTP.app -} defined in HTTP.app -}
appPortStr <- Configuration.appPort port <- Configuration.appPort
env <- Configuration.getRuntimeEnvironment env <- Configuration.getRuntimeEnvironment
let appPort = read appPortStr :: Int scotty (read port) (HTTP.app env)
scotty appPort (HTTP.app env)