From 03b76bddf2618ea2c42fd40f6b59be3208ad2726 Mon Sep 17 00:00:00 2001 From: absc Date: Tue, 23 Jul 2024 23:42:31 +0200 Subject: [PATCH] No need for the bucket to be configurable. While there, create the bucket for the users during initialization. --- dudeswave/src/dudeswave_app.erl | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/dudeswave/src/dudeswave_app.erl b/dudeswave/src/dudeswave_app.erl index a6082f1..39cef26 100644 --- a/dudeswave/src/dudeswave_app.erl +++ b/dudeswave/src/dudeswave_app.erl @@ -18,6 +18,9 @@ -export([start/2, stop/1]). +-define(APPBUCKET, dudeswave). +-define(USERSBUCKET, dudes). + start(_Type, StartArgs) -> {ok, Addr} = case application:get_env(ip) of {ok, AddrConf} -> inet:parse_address(AddrConf); @@ -26,19 +29,20 @@ start(_Type, StartArgs) -> {ok, Port} = application:get_env(port), - Bucket = case application:get_env(bucket) of - {ok, V} -> V; - false -> dudeswave + case storage:create(?APPBUCKET) of + ok -> bootstrap(?APPBUCKET); + {error, {already_exists, ?APPBUCKET, _}} -> ok; + _ -> exit(blog_storage_init_failed) end, - ok = case storage:create(Bucket) of - ok -> bootstrap(Bucket); - {error, {already_exists, Bucket, _}} -> ok; - _ -> exit(storage_bootstrap_failed) + case storage:create(?USERSBUCKET) of + ok -> ok; + {error, {already_exists, ?USERSBUCKET, _}} -> ok; + _ -> exit(users_init_failed) end, Dispatch = cowboy_router:compile([ - {'_', [{"/", dudeswave_handler, #{bucket => Bucket}}]} + {'_', [{"/", dudeswave_handler, #{bucket => ?APPBUCKET}}]} ]), {ok, ListenerPid} = cowboy:start_tls(dudeswave_listener, [