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
main-is: Main.hs
hs-source-dirs:
app
, src
src
default-extensions:
ConstraintKinds
DeriveGeneric
@ -64,5 +63,4 @@ executable Purr
Feature.Sharing.HTTP
Feature.Sharing.SQLite
Feature.Sharing.Templates
Lib
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
, confLinkLength, dataPath, dbPath
, encKey, getRuntimeEnvironment
, keyFileInit, main) where
, keyFileInit, init) where
import qualified Data.ByteString as B
import Control.Monad (mapM)
import Configuration.Dotenv
import Core.Types
import Crypto.Saltine.Core.SecretBox (newKey)
import Crypto.Saltine.Class (encode)
import Configuration.Dotenv
import Prelude hiding (init)
import System.Directory (doesFileExist)
import System.Environment (getEnv, lookupEnv)
-- Load environment variables from dotenv file if required
main :: IO ()
main = do
init :: IO ()
init = do
reqEnvLookup <- getRequiredEnv
if (Nothing `elem` reqEnvLookup)
then checkEnvFile requiredEnvVars

View File

@ -6,12 +6,13 @@ import Core.Types
import Data.ByteString as B
import Database.SQLite.Simple
import Database.SQLite.Simple.FromRow
import Prelude hiding (init)
import qualified Data.Text as T
-- Set up SQLite database table when Purr starts if it doesn't already exist
main :: IO ()
main = do
init :: IO ()
init = do
conn <- open dbPath
execute_ conn
"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.HTTP as HTTP
@ -16,17 +16,16 @@ main = do
-- Initialize the RNG used for sodium encryption (Saltine library)
sodiumInit
{- Initialize our dotenv configuration which reads from a .env configuration
file unless the PURRNOFILE env var exists already. -}
Configuration.main
if any required variables are missing from the provided environment -}
Configuration.init
{- Initialize the encryption key file if it doesn't
exist yet or use the existing key -}
Configuration.keyFileInit
{- Initialize our database by ensuring the SQLite file exists
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
defined in HTTP.app -}
appPortStr <- Configuration.appPort
port <- Configuration.appPort
env <- Configuration.getRuntimeEnvironment
let appPort = read appPortStr :: Int
scotty appPort (HTTP.app env)
scotty (read port) (HTTP.app env)