3
0

Always generate db tag (either from dbname or name)

This commit is contained in:
Denis Arh
2018-07-12 19:33:24 +02:00
parent d7d7ac3208
commit fd8efa0b2a
2 changed files with 11 additions and 1 deletions
+10
View File
@@ -81,3 +81,13 @@ foreach (array("routes") as $type) {
file_put_contents($filename, $contents);
}
// camel case to snake case
function decamel($input) {
preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
$ret = $matches[0];
foreach ($ret as &$match) {
$match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match);
}
return implode('_', $ret);
}
+1 -1
View File
@@ -20,7 +20,7 @@ type ({foreach $structs as $struct}
// {api.title}
{struct.name} struct {
{foreach $struct.fields as $field}
{field.name} {field.type}{if $field.tag || $field.dbname} `{$field.tag}{if $field.dbname} db:"{$field.dbname}"{/if}`{/if}{newline}
{field.name} {field.type} `{if $field.tag}{$field.tag} {/if}db:"{if $field.dbname}{$field.dbname}{else}{$field.name|decamel}{/if}"`{newline}
{/foreach}
changed []string