update generator, sort routes by alphabet
This commit is contained in:
38
sam/_gen.php
38
sam/_gen.php
@@ -5,24 +5,32 @@ error_reporting(E_ALL^E_NOTICE);
|
||||
|
||||
include("docs/vendor/autoload.php");
|
||||
|
||||
function array_change_key_case_recursive($arr) {
|
||||
return array_map(function ($item) {
|
||||
if (is_array($item)) {
|
||||
$item = array_change_key_case_recursive($item);
|
||||
}
|
||||
return $item;
|
||||
}, array_change_key_case($arr));
|
||||
}
|
||||
|
||||
$tpl = new Monotek\MiniTPL\Template;
|
||||
$tpl->set_compile_location("/tmp", true);
|
||||
$tpl->add_default("newline", "\n");
|
||||
|
||||
$apis = json_decode(file_get_contents("docs/src/spec.json"), true);
|
||||
foreach ($apis as $k => $v) {
|
||||
foreach ($v['apis'] as $kk => $vv) {
|
||||
$vv['path'] = "/" . $vv['name'];
|
||||
$v['apis'][$kk] = $vv;
|
||||
}
|
||||
$v['path'] = "/" . $v['entrypoint'];
|
||||
$apis[$k] = $v;
|
||||
}
|
||||
$api_files = glob("docs/src/spec/*.json");
|
||||
$apis = array_map(function($filename) {
|
||||
return array_change_key_case_recursive(json_decode(file_get_contents($filename), true));
|
||||
}, $api_files);
|
||||
|
||||
usort($apis, function($a, $b) {
|
||||
return strcmp($a['interface'], $b['interface']);
|
||||
});
|
||||
|
||||
foreach (array("structs", "handlers", "interfaces", "request", "") as $type) {
|
||||
foreach ($apis as $api) {
|
||||
if (!empty($api['struct'])) {
|
||||
$name = ucfirst($api['entrypoint']);
|
||||
$name = ucfirst($api['interface']);
|
||||
$filename = str_replace("..", ".", strtolower($name) . "." . $type . ".go");
|
||||
|
||||
$tpl->load("http_$type.tpl");
|
||||
@@ -37,13 +45,19 @@ foreach (array("structs", "handlers", "interfaces", "request", "") as $type) {
|
||||
$tpl->assign("calls", $api['apis']);
|
||||
$contents = $tpl->get();
|
||||
|
||||
file_put_contents($filename, $contents);
|
||||
$save = true;
|
||||
if ($type === "" && file_exists($filename)) {
|
||||
$save = false;
|
||||
}
|
||||
if ($save) {
|
||||
file_put_contents($filename, $contents);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (array("routes") as $type) {
|
||||
$name = ucfirst($api['entrypoint']);
|
||||
$name = ucfirst($api['interface']);
|
||||
$filename = str_replace("..", ".", $type . ".go");
|
||||
|
||||
$tpl->load("http_$type.tpl");
|
||||
|
||||
@@ -5,27 +5,12 @@ import (
|
||||
)
|
||||
|
||||
func MountRoutes(r chi.Router) {
|
||||
organisation := OrganisationHandlers{}.new()
|
||||
team := TeamHandlers{}.new()
|
||||
channel := ChannelHandlers{}.new()
|
||||
message := MessageHandlers{}.new()
|
||||
organisation := OrganisationHandlers{}.new()
|
||||
team := TeamHandlers{}.new()
|
||||
user := UserHandlers{}.new()
|
||||
websocket := WebsocketHandlers{}.new()
|
||||
r.Route("/organisation", func(r chi.Router) {
|
||||
r.Post("/edit", organisation.Edit)
|
||||
r.Delete("/remove", organisation.Remove)
|
||||
r.Get("/read", organisation.Read)
|
||||
r.Get("/search", organisation.Search)
|
||||
r.Post("/archive", organisation.Archive)
|
||||
})
|
||||
r.Route("/team", func(r chi.Router) {
|
||||
r.Post("/edit", team.Edit)
|
||||
r.Delete("/remove", team.Remove)
|
||||
r.Get("/read", team.Read)
|
||||
r.Get("/search", team.Search)
|
||||
r.Post("/archive", team.Archive)
|
||||
r.Post("/move", team.Move)
|
||||
})
|
||||
r.Route("/channel", func(r chi.Router) {
|
||||
r.Post("/edit", channel.Edit)
|
||||
r.Delete("/remove", channel.Remove)
|
||||
@@ -44,6 +29,21 @@ func MountRoutes(r chi.Router) {
|
||||
r.Post("/pin", message.Pin)
|
||||
r.Post("/flag", message.Flag)
|
||||
})
|
||||
r.Route("/organisation", func(r chi.Router) {
|
||||
r.Post("/edit", organisation.Edit)
|
||||
r.Delete("/remove", organisation.Remove)
|
||||
r.Get("/read", organisation.Read)
|
||||
r.Get("/search", organisation.Search)
|
||||
r.Post("/archive", organisation.Archive)
|
||||
})
|
||||
r.Route("/team", func(r chi.Router) {
|
||||
r.Post("/edit", team.Edit)
|
||||
r.Delete("/remove", team.Remove)
|
||||
r.Get("/read", team.Read)
|
||||
r.Get("/search", team.Search)
|
||||
r.Post("/archive", team.Archive)
|
||||
r.Post("/move", team.Move)
|
||||
})
|
||||
r.Route("/user", func(r chi.Router) {
|
||||
r.Post("/login", user.Login)
|
||||
r.Get("/search", user.Search)
|
||||
|
||||
Reference in New Issue
Block a user