No need for the bucket to be configurable.

While there, create the bucket for the users during initialization.
main
absc 2024-07-23 23:42:31 +02:00
parent 3280596836
commit 03b76bddf2
1 changed files with 12 additions and 8 deletions

View File

@ -18,6 +18,9 @@
-export([start/2, stop/1]). -export([start/2, stop/1]).
-define(APPBUCKET, dudeswave).
-define(USERSBUCKET, dudes).
start(_Type, StartArgs) -> start(_Type, StartArgs) ->
{ok, Addr} = case application:get_env(ip) of {ok, Addr} = case application:get_env(ip) of
{ok, AddrConf} -> inet:parse_address(AddrConf); {ok, AddrConf} -> inet:parse_address(AddrConf);
@ -26,19 +29,20 @@ start(_Type, StartArgs) ->
{ok, Port} = application:get_env(port), {ok, Port} = application:get_env(port),
Bucket = case application:get_env(bucket) of case storage:create(?APPBUCKET) of
{ok, V} -> V; ok -> bootstrap(?APPBUCKET);
false -> dudeswave {error, {already_exists, ?APPBUCKET, _}} -> ok;
_ -> exit(blog_storage_init_failed)
end, end,
ok = case storage:create(Bucket) of case storage:create(?USERSBUCKET) of
ok -> bootstrap(Bucket); ok -> ok;
{error, {already_exists, Bucket, _}} -> ok; {error, {already_exists, ?USERSBUCKET, _}} -> ok;
_ -> exit(storage_bootstrap_failed) _ -> exit(users_init_failed)
end, end,
Dispatch = cowboy_router:compile([ Dispatch = cowboy_router:compile([
{'_', [{"/", dudeswave_handler, #{bucket => Bucket}}]} {'_', [{"/", dudeswave_handler, #{bucket => ?APPBUCKET}}]}
]), ]),
{ok, ListenerPid} = cowboy:start_tls(dudeswave_listener, [ {ok, ListenerPid} = cowboy:start_tls(dudeswave_listener, [