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