do not force file to exist
This commit is contained in:
parent
4bd924d65f
commit
5ec03d06c2
1 changed files with 16 additions and 18 deletions
34
src/app.ml
34
src/app.ml
|
|
@ -20,14 +20,13 @@ let config_dir =
|
|||
|
||||
let config =
|
||||
let filename = Filename.concat config_dir "config.scfg" in
|
||||
if not @@ Sys.file_exists filename then
|
||||
failwith
|
||||
@@ Format.sprintf "configuration file `%s` does not exist, please create it"
|
||||
filename;
|
||||
Dream.log "config file: %s" filename;
|
||||
match Scfg.Parse.from_file filename with
|
||||
| Error e -> failwith e
|
||||
| Ok config -> config
|
||||
if not @@ Sys.file_exists filename then []
|
||||
else begin
|
||||
Dream.log "config file: %s" filename;
|
||||
match Scfg.Parse.from_file filename with
|
||||
| Error e -> failwith e
|
||||
| Ok config -> config
|
||||
end
|
||||
|
||||
let open_registration =
|
||||
match Scfg.Query.get_dir "open_registration" config with
|
||||
|
|
@ -59,8 +58,9 @@ let port =
|
|||
let () = Dream.log "port: %d" port
|
||||
|
||||
let hostname =
|
||||
let default_hostname = Format.sprintf "localhost:%d" port in
|
||||
match Scfg.Query.get_dir "hostname" config with
|
||||
| None -> Format.sprintf "localhost:%d" port
|
||||
| None -> default_hostname
|
||||
| Some hostname ->
|
||||
Result.fold ~error:failwith ~ok:Fun.id (Scfg.Query.get_param 0 hostname)
|
||||
|
||||
|
|
@ -78,17 +78,15 @@ let log =
|
|||
|
||||
let () = Dream.log "log: %b" log
|
||||
|
||||
let get_dirs name =
|
||||
let dirs = Scfg.Query.get_dirs name config in
|
||||
List.map
|
||||
(fun dir ->
|
||||
Result.fold ~error:failwith ~ok:Fun.id (Scfg.Query.get_param 0 dir) )
|
||||
dirs
|
||||
|
||||
let random_state = Random.State.make_self_init ()
|
||||
|
||||
let () = Random.set_state random_state
|
||||
|
||||
let about =
|
||||
(* TODO read from about.txt *)
|
||||
"This is pellest"
|
||||
let default_about = "Pellest is great !" in
|
||||
match Scfg.Query.get_dir "about" config with
|
||||
| None -> default_about
|
||||
| Some about -> (
|
||||
match Scfg.Query.get_param 0 about with
|
||||
| Error e -> failwith e
|
||||
| Ok about -> about )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue