This application provides fuzzy search server for data stored in JSON format.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

69 lines
2.7 KiB

{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE Unsafe #-}
-- -----------------------------------------------------------------------------
-- Copyright (C) 2019, Maxim Lihachev, <envrm@yandex.ru>
--
-- This program is free software: you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the Free
-- Software Foundation, version 3.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- -----------------------------------------------------------------------------
--
-- | Json-search service
--
module Main (main) where
import Relude ( Maybe (Nothing), Bool (False), IO, ($), id, null )
import System.Exit ( die )
import System.Environment ( getArgs, withArgs )
import System.Console.CmdArgs ( cmdArgs, help, summary, typ, name, program, (&=) )
import Text.Pretty.Simple ( pPrint )
import Server ( startServer, ServerSettings (ServerSettings, file, cached, logs, port), checkJsonFile )
-- -----------------------------------------------------------------------------
--
-- | Default command line arguments
--
defaultSettings :: IO ServerSettings
defaultSettings = cmdArgs
$ ServerSettings { port = 3000 &= typ "3000" &= help "Search server port"
, logs = "apache" &= typ "apache" &= help "apache | simple | json | disable | full"
, cached = False &= typ "False" &= help "Store Json data into memory" &= name "cached"
, file = Nothing &= typ "data.json" &= help "Json file name" &= name "json"
} &= program "json-search-server"
&= summary "json-search-server v0.1.0: seach server for Json"
-- -----------------------------------------------------------------------------
--
-- | Start application
--
main :: IO ()
main = do
args <- getArgs
settings <- (if null args then withArgs ["--help"] else id) defaultSettings
pPrint settings
let fileStatus = checkJsonFile (file settings) in
case fileStatus of
"ok" ->
startServer settings
_err ->
die fileStatus