@@ -64,27 +64,27 @@ pub const FortunesEndpoint = struct {
6464 defer conn .release ();
6565
6666 var rows = try conn .query ("SELECT id, message FROM Fortune" , .{});
67- rows .deinit ();
67+ defer rows .deinit ();
6868
6969 var fortunes = std .ArrayList (Fortune ).init (middleware .SharedAllocator .getAllocator ());
7070 defer fortunes .deinit ();
7171
7272 while (try rows .next ()) | row | {
73- var fortune = Fortune { .id = row .get (i32 , 0 ), .message = row .get ([]const u8 , 1 ) };
74- _ = try fortunes .append (fortune );
73+ const fortune = Fortune { .id = row .get (i32 , 0 ), .message = row .get ([]const u8 , 1 ) };
74+ try fortunes .append (fortune );
7575 }
7676
77- var fortune = Fortune { .id = 0 , .message = "Additional fortune added at request time." };
78- _ = try fortunes .append (fortune );
77+ const fortune = Fortune { .id = 0 , .message = "Additional fortune added at request time." };
78+ try fortunes .append (fortune );
7979
80- var fortunes_slice = try fortunes .toOwnedSlice ();
80+ const fortunes_slice = try fortunes .toOwnedSlice ();
8181 std .mem .sort (Fortune , fortunes_slice , {}, cmpFortuneByMessage );
8282
8383 return fortunes_slice ;
8484 }
8585
8686 fn getFortunesHtml (self : * Self , pool : * pg.Pool ) ! []const u8 {
87- var fortunes = try getFortunes (pool );
87+ const fortunes = try getFortunes (pool );
8888
8989 self .mutex .lock ();
9090 const ret = self .mustache .build (.{ .fortunes = fortunes });
@@ -95,15 +95,15 @@ pub const FortunesEndpoint = struct {
9595
9696 // std.debug.print("mustache output {s}\n", .{raw});
9797
98- var html = try deescapeHtml (raw );
98+ const html = try deescapeHtml (raw );
9999
100100 // std.debug.print("html output {s}\n", .{html});
101101
102102 return html ;
103103 }
104104
105105 pub fn get (ep : * zap.Endpoint , req : zap.Request ) void {
106- const self = @fieldParentPtr (Self , "ep" , ep );
106+ const self : * FortunesEndpoint = @fieldParentPtr ("ep" , ep );
107107
108108 if (! checkPath (ep , req )) return ;
109109
@@ -118,7 +118,7 @@ pub const FortunesEndpoint = struct {
118118 }
119119 }
120120
121- var fortunes_html = getFortunesHtml (self , pool ) catch return ;
121+ const fortunes_html = getFortunesHtml (self , pool ) catch return ;
122122
123123 req .sendBody (fortunes_html ) catch return ;
124124
@@ -146,7 +146,7 @@ pub const DbEndpoint = struct {
146146 }
147147
148148 pub fn get (ep : * zap.Endpoint , req : zap.Request ) void {
149- const self = @fieldParentPtr (Self , "ep" , ep );
149+ const self : * DbEndpoint = @fieldParentPtr ("ep" , ep );
150150
151151 if (! checkPath (ep , req )) return ;
152152
@@ -177,14 +177,13 @@ pub const DbEndpoint = struct {
177177 var conn = pool .acquire () catch return ;
178178 defer conn .release ();
179179
180- var row_result = conn .row ("SELECT id, randomNumber FROM World WHERE id = $1" , .{random_number }) catch | err | {
180+ const row_result = conn .row ("SELECT id, randomNumber FROM World WHERE id = $1" , .{random_number }) catch | err | {
181181 std .debug .print ("Error querying database: {}\n " , .{err });
182182 return ;
183183 };
184184 var row = row_result .? ;
185- defer row .deinit ();
186185
187- var world = World { .id = row .get (i32 , 0 ), .randomNumber = row .get (i32 , 1 ) };
186+ const world = World { .id = row .get (i32 , 0 ), .randomNumber = row .get (i32 , 1 ) };
188187
189188 var buf : [100 ]u8 = undefined ;
190189 var json_to_send : []const u8 = undefined ;
@@ -218,7 +217,7 @@ pub const PlaintextEndpoint = struct {
218217 }
219218
220219 pub fn get (ep : * zap.Endpoint , req : zap.Request ) void {
221- const self = @fieldParentPtr (Self , "ep" , ep );
220+ const self : * PlaintextEndpoint = @fieldParentPtr ("ep" , ep );
222221 _ = self ;
223222
224223 if (! checkPath (ep , req )) return ;
@@ -248,14 +247,14 @@ pub const JsonEndpoint = struct {
248247 }
249248
250249 pub fn get (ep : * zap.Endpoint , req : zap.Request ) void {
251- const self = @fieldParentPtr (Self , "ep" , ep );
250+ const self : * JsonEndpoint = @fieldParentPtr ("ep" , ep );
252251 _ = self ;
253252
254253 if (! checkPath (ep , req )) return ;
255254
256255 req .setContentType (.JSON ) catch return ;
257256
258- var message = Message { .message = "Hello, World!" };
257+ const message = Message { .message = "Hello, World!" };
259258
260259 var buf : [100 ]u8 = undefined ;
261260 var json_to_send : []const u8 = undefined ;
0 commit comments