%%%------------------------------------------------------------------- %%% @doc Обработчик проверки здоровья клиентского API. %%% GET – возвращает статус сервера и build identity. %%% @end %%%------------------------------------------------------------------- -module(handler_health). -behaviour(cowboy_handler). -export([init/2]). -export([trails/0]). %%% cowboy_handler callback -spec init(cowboy_req:req(), any()) -> {ok, cowboy_req:req(), any()}. init(Req, Opts) -> handle(Req, Opts). %%% Swagger metadata -spec trails() -> [map()]. trails() -> [ #{ path => <<"/health">>, method => <<"GET">>, description => <<"API health check with build identity">>, tags => [<<"Health">>], responses => #{ 200 => #{ description => <<"API is healthy">>, content => #{<<"application/json">> => #{schema => #{ type => object, properties => #{ status => #{type => string}, service => #{type => string}, version => #{type => string, description => <<"MAJOR.MINOR from EventHubSpec/VERSION">>}, build => #{type => integer, description => <<"CI run_number (per-repo)">>}, git_sha => #{type => string}, built_at => #{type => string} } }}} } } } ]. %%%=================================================================== %%% Внутренние функции %%%=================================================================== %% @private -spec handle(cowboy_req:req(), any()) -> {ok, cowboy_req:req(), any()}. handle(Req, _Opts) -> case cowboy_req:method(Req) of <<"GET">> -> handler_utils:send_json(Req, 200, eventhub_build_info:info()); _ -> handler_utils:send_error(Req, 405, <<"Method not allowed">>) end.