const std = @import("std"); const endpoints = @import("endpoints"); pub const ctx = @import("context"); const sec = @import("security"); const services = @import("services"); const HttpService = services.HttpService; const server = @import("server.zig"); const PaymentIntegrator = @import("payment_integrator.zig").PaymentIntegrator; pub fn main() !void { var get_endpoints = endpoints.EndpointsManager{}; var post_endpoints = endpoints.EndpointsManager{}; var put_endpoints = endpoints.EndpointsManager{}; std.debug.print("Init context\n", .{}); try ctx.init(); defer ctx.deinit(); std.debug.print("Context: OK\n", .{}); sec.updateToken(ctx.config.initial_token); try endpoints.payments.registerEndpoints(&get_endpoints, &post_endpoints); std.debug.print("Endpionts: OK\n", .{}); std.debug.print("default_pool: {d}\n", .{ctx.config.default_pool}); std.debug.print("fallback_pool: {d}\n", .{ctx.config.fallback_pool}); var default_service = try HttpService.init(1, "default", ctx.config.default_host, ctx.config.default_port, ctx.config.default_pool, std.heap.page_allocator); var fallback_service = try HttpService.init(2, "fallback", ctx.config.fallback_host, ctx.config.fallback_port, ctx.config.fallback_pool, std.heap.page_allocator); var service_pool = services.ServicePool{}; defer default_service.deinit(); defer fallback_service.deinit(); try service_pool.add(&default_service); try service_pool.add(&fallback_service); var integrator = PaymentIntegrator.init(&service_pool); try default_service.start(); try fallback_service.start(); try integrator.start(); std.debug.print("Service And Integrator: OK\n", .{}); ctx.payments_repository.subscribeInsert(&PaymentIntegrator.newPaymentEvent); var ip_map: []const u8 = "127.0.0.1"; if (ctx.config.env == .PROD) ip_map = "0.0.0.0"; std.log.info("Server Enviroment: {}\n", .{ctx.config.env}); var myserver = try server.HttpServer.init(ip_map, ctx.config.port, &get_endpoints, &post_endpoints, &put_endpoints); std.debug.print("Init server: OK\n", .{}); std.Thread.sleep(1_000_000 * 1000 * 4); try myserver.start(); std.debug.print("Server Started: OK\n", .{}); } test { std.testing.refAllDecls(@This()); }