Something went wrong. Try again.
A Haskell Webserver Template
Something went wrong. Try again.
1.4 kB · 42 lines
Haskell
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243module Webserver.Data.Context where
----------------------------------------------------------------------------------------------------
import qualified Hasql.Pool as Poolimport qualified Jose.Jwk as JWKimport qualified System.Environment as Envimport qualified Webserver.Data.Mode as Modeimport qualified Webserver.Data.Sql.Cache.Session as Sessionimport Webserver.Data.Telemetry (TelemetryState)
----------------------------------------------------------------------------------------------------
{- A Context type. Created on app initialization and follows you around the app. Use this when you can't guarantee you'll have access to IO, since you need that for `getEnv`-}data Context = Context { mode :: !Mode.Mode , jwtKey :: !JWK.Jwk , dbPool :: !Pool.Pool , telemetry :: !TelemetryState }
instance Show Context where show ctx = "Context { mode = " <> show ctx.mode <> ", dbPool = <Pool>" <> ", telemetry = <TelemetryState> }"
----------------------------------------------------------------------------------------------------
loadContext :: Pool.Pool -> TelemetryState -> IO ContextloadContext pool telemetrySt = do mode_ <- Env.getEnv "MODE" key <- Session.jwk return <| Context (Mode.modeFromString mode_) key pool telemetrySt