Skip to content

Commit e2f3e8b

Browse files
committed
app: update for latest tk
1 parent 3cda6aa commit e2f3e8b

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

src/app.zig

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ pub const App = struct {
110110
logger: Logger,
111111
config: std.json.Parsed(Config),
112112
db_pool: fr.Pool(fr.SQLite3),
113-
llama: llama.Pool,
114-
client: std.http.Client,
113+
llama: llama.Pool, // TODO: extract to standalone module
114+
client: std.http.Client, // TODO: switch to tk.Client
115115
server: tk.Server,
116116

117117
const CONFIG_FILE = "config.json";
@@ -124,6 +124,27 @@ pub const App = struct {
124124
inline for (std.meta.fields(Config)) |f| try ct.register(&@field(target.value, f.name));
125125
}
126126

127+
pub fn initServer(target: *tk.Server, allocator: std.mem.Allocator, cfg: @FieldType(Config, "server"), injector: *tk.Injector) !void {
128+
target.* = try tk.Server.init(allocator, routes, .{
129+
.listen = cfg,
130+
.injector = injector,
131+
});
132+
}
133+
134+
pub fn afterAppInit(allocator: std.mem.Allocator, db_pool: *fr.Pool(fr.SQLite3), client: *std.http.Client) !void {
135+
var db = try db_pool.getSession(allocator);
136+
defer db.deinit();
137+
138+
try fr.migrate(db, @embedFile("db_schema.sql"));
139+
140+
if (comptime builtin.target.os.tag == .windows) {
141+
try client.ca_bundle.rescan(allocator);
142+
const start = client.ca_bundle.bytes.items.len;
143+
try client.ca_bundle.bytes.appendSlice(allocator, @embedFile("amazon1.cer"));
144+
try client.ca_bundle.parseCert(allocator, @intCast(start), std.time.timestamp());
145+
}
146+
}
147+
127148
pub fn updateConfig(self: *App, config: Config) !void {
128149
// thread-safety!
129150
self.mutex.lock();
@@ -163,24 +184,6 @@ pub const App = struct {
163184
file.writer(),
164185
);
165186
}
166-
167-
pub fn initClient(target: *std.http.Client, allocator: std.mem.Allocator) !void {
168-
target.* = .{ .allocator = allocator };
169-
170-
if (builtin.target.os.tag == .windows) {
171-
try target.ca_bundle.rescan(allocator);
172-
const start = target.ca_bundle.bytes.items.len;
173-
try target.ca_bundle.bytes.appendSlice(allocator, @embedFile("amazon1.cer"));
174-
try target.ca_bundle.parseCert(allocator, @intCast(start), std.time.timestamp());
175-
}
176-
}
177-
178-
pub fn initServer(target: *tk.Server, allocator: std.mem.Allocator, cfg: @FieldType(Config, "server"), injector: *tk.Injector) !void {
179-
target.* = try tk.Server.init(allocator, routes, .{
180-
.listen = cfg,
181-
.injector = injector,
182-
});
183-
}
184187
};
185188

186189
const api: tk.Route = .group("/api", &.{

0 commit comments

Comments
 (0)