Просмотр исходного кода

refactor: change confs for dashboard listeners from array to map

Don't use arrays in the config path to make it easier to change
configs via environments varibles.
Shawn 3 лет назад
Родитель
Сommit
8e6b98af68

Разница между файлами не показана из-за своего большого размера
+ 23 - 28
apps/emqx_dashboard/etc/emqx_dashboard.conf


+ 4 - 10
apps/emqx_dashboard/src/emqx_dashboard.erl

@@ -155,16 +155,10 @@ apps() ->
     ].
 
 listeners(Listeners) ->
-    [
-        begin
-            Protocol = maps:get(protocol, ListenerOption0, http),
-            {ListenerOption, Bind} = ip_port(ListenerOption0),
-            Name = listener_name(Protocol, ListenerOption),
-            RanchOptions = ranch_opts(maps:without([protocol], ListenerOption)),
-            {Name, Protocol, Bind, RanchOptions}
-        end
-     || ListenerOption0 <- Listeners
-    ].
+    lists:map(fun({Protocol, Conf}) ->
+            {Conf1, Bind} = ip_port(Conf),
+            {listener_name(Protocol, Conf1), Protocol, Bind, ranch_opts(Conf1)}
+        end, maps:to_list(Listeners)).
 
 ip_port(Opts) -> ip_port(maps:take(bind, Opts), Opts).
 

+ 19 - 12
apps/emqx_dashboard/src/emqx_dashboard_schema.erl

@@ -31,12 +31,7 @@ fields("dashboard") ->
     [
         {listeners,
             sc(
-                hoconsc:array(
-                    hoconsc:union([
-                        hoconsc:ref(?MODULE, "http"),
-                        hoconsc:ref(?MODULE, "https")
-                    ])
-                ),
+                ref("listeners"),
                 #{
                     desc =>
                         "HTTP(s) listeners are identified by their protocol type and are\n"
@@ -71,17 +66,27 @@ fields("dashboard") ->
         {cors, fun cors/1},
         {i18n_lang, fun i18n_lang/1}
     ];
-fields("http") ->
+fields("listeners") ->
     [
-        {"protocol",
+        {"http",
             sc(
-                hoconsc:enum([http, https]),
+                ref("http"),
                 #{
-                    desc => ?DESC("protocol"),
-                    required => true,
-                    default => http
+                    desc => "TCP listeners",
+                    required => {false, recursively}
                 }
             )},
+        {"https",
+            sc(
+                ref("https"),
+                #{
+                    desc => "SSL listeners",
+                    required => {false, recursively}
+                }
+            )}
+    ];
+fields("http") ->
+    [
         {"bind", fun bind/1},
         {"num_acceptors",
             sc(
@@ -201,3 +206,5 @@ i18n_lang(desc) -> "Internationalization language support.";
 i18n_lang(_) -> undefined.
 
 sc(Type, Meta) -> hoconsc:mk(Type, Meta).
+
+ref(Field) -> hoconsc:ref(?MODULE, Field).