use otmp
use http
use http.server {Req :: Request, Res :: Response, route}
-use json
+use core.encoding.json
#inject runtime.vars {
Enable_Heap_Debug :: true
@route.{.GET, "/news"}
(req: &Req, res: &Res) {
Article :: struct { name, description, path, date: str }
- articles := make([..] Article);
+ articles: [] Article;
article_file := os.get_contents("www/news-articles/index.json");
article_index, json_err := json.decode_with_error(article_file);
return;
}
- for article_index.root->as_array() {
- name := it["name"]->as_str();
- desc := it["description"]->as_str();
- path := it["path"]->as_str();
- date := it["date"]->as_str();
- articles << .{ name, desc, path, date };
- }
+ json.as_any(article_index.root, &articles);
res->render("pages/news", &.{
articles = articles