Always generate db tag (either from dbname or name)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user