siga

Sistema Interativo de GerĂȘncia de Atividades.
Log | Files | Refs | README | LICENSE

main.zig (1410B)


      1 const std = @import("std");
      2 const Io = std.Io;
      3 const server = @import("server");
      4 const auth = @import("auth");
      5 const options = @import("options");
      6 
      7 pub fn main(init: std.process.Init) !void {
      8     const io = init.io;
      9     const allocator = init.gpa;
     10 
     11     const args = try init.minimal.args.toSlice(init.arena.allocator());
     12     var diag: options.Diagnostic = .{};
     13     const opts = options.parse(args[1..], &diag) catch |err| {
     14         switch (err) {
     15             error.HelpRequested => {
     16                 std.debug.print("{s}", .{options.usage});
     17                 return;
     18             },
     19             error.UnknownFlag => std.debug.print("unknown argument: {s}\n", .{diag.arg}),
     20             error.MissingValue => std.debug.print("missing value for {s}\n", .{diag.arg}),
     21             error.InvalidPort => std.debug.print("invalid port: {s}\n", .{diag.arg}),
     22         }
     23         std.debug.print("{s}", .{options.usage});
     24         std.process.exit(2);
     25     };
     26 
     27     const address = options.resolveAddress(io, opts.address, opts.port) catch {
     28         std.debug.print("invalid address: {s} (use localhost or an IP)\n", .{opts.address});
     29         std.process.exit(2);
     30     };
     31 
     32     // Base URL of the Go auth service.
     33     const auth_url = init.environ_map.get("SIGA_AUTH_URL") orelse auth.default_url;
     34 
     35     var server_future = Io.async(io, server.start, .{ io, allocator, address, auth_url });
     36     _ = try server_future.await(io);
     37 }