A SpaceTraders Agent
at main 1.5 kB view raw
1const std = @import("std"); 2 3const pretty = @import("meta").pretty; 4 5const meta = @import("meta"); 6 7const st = @import("st"); 8const api = st.api; 9const Client = st.http.Client; 10 11const agent = @import("agent"); 12const Config = agent.config.Config; 13 14pub const known_folders_config: @import("known-folders").KnownFolderConfig = .{ 15 .xdg_on_mac = true, 16}; 17 18fn juicyMain( 19 gpa: std.mem.Allocator, 20 io: std.Io, 21 config: *const Config, 22 client: *Client, 23) !void { 24 _ = gpa; 25 _ = config; 26 // _ = io; 27 // _ = client; 28 29 var fleet_f = try api.fleet.listShips(client, .{}); 30 defer _ = fleet_f.cancel(io) catch {}; 31 32 const fleet = try fleet_f.await(io); 33 defer fleet.deinit(); 34 35 std.log.info("{f}", .{pretty(fleet.value)}); 36} 37 38pub fn main() !void { 39 var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 40 defer _ = gpa.deinit(); 41 const allocator = gpa.allocator(); 42 43 var io_impl: std.Io.Threaded = .init(allocator); 44 defer io_impl.deinit(); 45 const io = io_impl.io(); 46 47 std.log.debug("Io threads: {}", .{io_impl.concurrent_limit.toInt() orelse 0}); 48 49 const config = try agent.config.load(io, allocator); 50 defer agent.config.free(allocator, config); 51 52 var client = Client.init(allocator, io, .{ 53 .auth = config.auth, 54 // .base_url = "http://localhost:4000/test", 55 // .base_url = "https://api.staging.spacetraders.io/v2", 56 }); 57 defer client.deinit(); 58 59 try juicyMain(allocator, io, &config, &client); 60}