Version endpoint
This commit is contained in:
1 parent
b38294c784
commit
e87aae3144
4 files changed
+53
-11
No files matched your search
+8
-2
@@ -21,6 +21,7 @@ import System.Metrics.Distribution qualified as D
|
||||
import UnliftIO (liftIO)
|
||||
import UnliftIO.IORef (readIORef)
|
||||
import Data.Coerce (coerce)
|
||||
import Version (Version, version)
|
||||
|
||||
data Health
|
||||
= OK
|
||||
@@ -57,7 +58,8 @@ newtype Metrics = Metrics (HashMap Text SampleValue)
|
||||
|
||||
data WallabagRoutes mode = WallabagRoutes
|
||||
{ _getHealth :: mode :- "health" :> Get '[PlainText, JSON] Health,
|
||||
_getMetrics :: mode :- "metrics" :> Get '[JSON] Metrics
|
||||
_getMetrics :: mode :- "metrics" :> Get '[JSON] Metrics,
|
||||
_getVersion :: mode :- "metrics" :> Get '[JSON] Version
|
||||
}
|
||||
deriving (Generic)
|
||||
|
||||
@@ -67,12 +69,16 @@ wallabagServer :: IORef Health -> WallabagRoutes (AsServerT M)
|
||||
wallabagServer health =
|
||||
WallabagRoutes
|
||||
{ _getHealth = getHealth health,
|
||||
_getMetrics = getMetrics
|
||||
_getMetrics = getMetrics,
|
||||
_getVersion = getVersion
|
||||
}
|
||||
|
||||
getHealth :: IORef Health -> M Health
|
||||
getHealth = readIORef
|
||||
|
||||
getVersion :: M Version
|
||||
getVersion = pure version -- Comes from TH during compile time
|
||||
|
||||
getMetrics :: M Metrics
|
||||
getMetrics = do
|
||||
sample <- view metricsStore >>= liftIO . EKG.sampleAll
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
|
||||
{-# HLINT ignore "Unused LANGUAGE pragma" #-}
|
||||
module Version where
|
||||
|
||||
import GitHash (tGitInfoCwd, giHash, giDirty, giCommitDate, giCommitMessage)
|
||||
import qualified Data.Aeson as A
|
||||
import qualified Data.ByteString.Lazy.Char8 as BL
|
||||
import GHC.Generics (Generic)
|
||||
|
||||
|
||||
-- Populate the version via the 'githash' package
|
||||
data Version = Version
|
||||
{ versionCommit :: String
|
||||
, versionDirty :: Bool
|
||||
, versionCommitDate :: String
|
||||
, versionCommitMessage :: String
|
||||
}
|
||||
deriving (Show, Generic)
|
||||
|
||||
instance A.ToJSON Version
|
||||
|
||||
version :: Version
|
||||
version = Version
|
||||
{ versionCommit = giHash gi
|
||||
, versionDirty = giDirty gi
|
||||
, versionCommitDate = giCommitDate gi
|
||||
, versionCommitMessage = giCommitMessage gi
|
||||
}
|
||||
where
|
||||
gi = $$tGitInfoCwd
|
||||
|
||||
test :: IO ()
|
||||
test = BL.putStrLn $ A.encode version
|
||||
Reference in new issue
Block a user