diff --git a/codegen/sam b/codegen/sam deleted file mode 120000 index b6e47f999..000000000 --- a/codegen/sam +++ /dev/null @@ -1 +0,0 @@ -crm \ No newline at end of file diff --git a/codegen/sam/rest/index.php b/codegen/sam/rest/index.php new file mode 100644 index 000000000..4869b8b54 --- /dev/null +++ b/codegen/sam/rest/index.php @@ -0,0 +1,31 @@ +load("http_.tpl"); + $tpl->assign($common); + $tpl->assign("package", basename(__DIR__)); + $tpl->assign("name", $name); + $tpl->assign("api", $api); + $tpl->assign("self", strtolower(substr($name, 0, 1))); + $tpl->assign("structs", $api['struct']); + $imports = array(); + foreach ($api['struct'] as $struct) { + if (isset($struct['imports'])) + foreach ($struct['imports'] as $import) { + $imports[] = $import; + } + } + $tpl->assign("imports", $imports); + $tpl->assign("calls", $api['apis']); + $contents = str_replace("\n\n}", "\n}", $tpl->get()); + + if (!file_exists($filename)) { + file_put_contents($filename, $contents); + echo $filename . "\n"; + } + } +} diff --git a/codegen/sam/rest/server/index.php b/codegen/sam/rest/server/index.php new file mode 100644 index 000000000..190ff7c1f --- /dev/null +++ b/codegen/sam/rest/server/index.php @@ -0,0 +1,46 @@ + function($name, $api) { + return strtolower($name) . ".go"; + }, + "http_request.tpl" => function($name, $api) { + return strtolower($name) . "_requests.go"; + }, + "http_handlers.tpl" => function($name, $api) { + return strtolower($name) . "_handlers.go"; + }, + "http_routes.tpl" => function($name, $api) { + return strtolower($name) . "_routes.go"; + } +); + +foreach ($templates as $template => $fn) +foreach ($apis as $api) { + if (is_array($api['struct'])) { + $name = ucfirst($api['interface']); + $filename = $dirname . "/" . $fn($name, $api); + + $tpl->load($template); + $tpl->assign($common); + $tpl->assign("package", basename(__DIR__)); + $tpl->assign("name", $name); + $tpl->assign("api", $api); + $tpl->assign("apis", $apis); + $tpl->assign("self", strtolower(substr($name, 0, 1))); + $tpl->assign("structs", $api['struct']); + $imports = array(); + foreach ($api['struct'] as $struct) { + if (isset($struct['imports'])) + foreach ($struct['imports'] as $import) { + $imports[] = $import; + } + } + $tpl->assign("imports", $imports); + $tpl->assign("calls", $api['apis']); + $contents = str_replace("\n\n}", "\n}", $tpl->get()); + + file_put_contents($filename, $contents); + echo $filename . "\n"; + } +}