Skip to content

Commit 0c73d2b

Browse files
committed
style(golang): remove trailing semicolons
1 parent f66c23f commit 0c73d2b

File tree

1 file changed

+53
-53
lines changed

1 file changed

+53
-53
lines changed

src/templates/routes.go.ejs

+53-53
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import "github.com/jmoiron/sqlx"
2020
// } => [ 'nameRu' ]
2121
function extractSelectParameters(queryAst) {
2222
return queryAst.columns
23-
.map(column => column.as !== null ? column.as : column.expr.column);
23+
.map(column => column.as !== null ? column.as : column.expr.column)
2424
}
2525
2626
// {'values':
@@ -34,8 +34,8 @@ function extractSelectParameters(queryAst) {
3434
function extractInsertValues(queryAst) {
3535
const values = queryAst.values.flatMap(elem => elem.value)
3636
.map(elem => elem.type === 'param' ? elem.value : null)
37-
.filter(elem => elem); // filter out nulls
38-
return Array.from(new Set(values));
37+
.filter(elem => elem) // filter out nulls
38+
return Array.from(new Set(values))
3939
}
4040
4141
// {'set':
@@ -56,27 +56,27 @@ function extractUpdateValues(queryAst) {
5656
// LATER: consider taking into account b.params from WHERE clause
5757
function extractProperties(queryAst) {
5858
if (queryAst.type === 'select') {
59-
return extractSelectParameters(queryAst);
59+
return extractSelectParameters(queryAst)
6060
}
6161
6262
if (queryAst.type === 'insert') {
63-
return extractInsertValues(queryAst);
63+
return extractInsertValues(queryAst)
6464
}
6565
6666
if (queryAst.type === 'update') {
67-
return extractUpdateValues(queryAst);
67+
return extractUpdateValues(queryAst)
6868
}
6969
70-
return [];
70+
return []
7171
}
7272
7373
function findOutType(fieldsInfo, fieldName) {
74-
const defaultType = '*string';
75-
const hasTypeInfo = fieldsInfo.hasOwnProperty(fieldName) && fieldsInfo[fieldName].hasOwnProperty('type');
74+
const defaultType = '*string'
75+
const hasTypeInfo = fieldsInfo.hasOwnProperty(fieldName) && fieldsInfo[fieldName].hasOwnProperty('type')
7676
if (hasTypeInfo && fieldsInfo[fieldName].type === 'integer') {
77-
return '*int';
77+
return '*int'
7878
}
79-
return defaultType;
79+
return defaultType
8080
}
8181
8282
function addTypes(props, fieldsInfo) {
@@ -85,23 +85,23 @@ function addTypes(props, fieldsInfo) {
8585
"name": prop,
8686
"type": findOutType(fieldsInfo, prop),
8787
}
88-
});
88+
})
8989
}
9090
9191
function query2dto(parser, method) {
92-
const query = removePlaceholders(method.query);
93-
const queryAst = parser.astify(query);
94-
const props = extractProperties(queryAst);
92+
const query = removePlaceholders(method.query)
93+
const queryAst = parser.astify(query)
94+
const props = extractProperties(queryAst)
9595
if (props.length === 0) {
96-
console.warn('Could not create DTO for query:', formatQuery(query));
97-
console.debug('Query AST:');
98-
console.debug(queryAst);
99-
return null;
96+
console.warn('Could not create DTO for query:', formatQuery(query))
97+
console.debug('Query AST:')
98+
console.debug(queryAst)
99+
return null
100100
}
101-
const fieldsInfo = method.dto && method.dto.fields ? method.dto.fields : {};
102-
const propsWithTypes = addTypes(props, fieldsInfo);
103-
const hasName = method.dto && method.dto.name && method.dto.name.length > 0;
104-
const name = hasName ? method.dto.name : "Dto" + ++globalDtoCounter;
101+
const fieldsInfo = method.dto && method.dto.fields ? method.dto.fields : {}
102+
const propsWithTypes = addTypes(props, fieldsInfo)
103+
const hasName = method.dto && method.dto.name && method.dto.name.length > 0
104+
const name = hasName ? method.dto.name : "Dto" + ++globalDtoCounter
105105
return {
106106
"name": name,
107107
"hasUserProvidedName": hasName,
@@ -112,33 +112,33 @@ function query2dto(parser, method) {
112112
// [ {name:foo, type:int}, {name:bar, type:string} ] => "foo=int bar=string"
113113
// LATER: sort before join
114114
"signature": propsWithTypes.map(field => `${field.name}=${field.type}`).join(' ')
115-
};
115+
}
116116
}
117117
118118
function dto2struct(dto) {
119-
let result = `type ${dto.name} struct {\n`;
119+
let result = `type ${dto.name} struct {\n`
120120
dto.props.forEach(prop => {
121-
const fieldName = capitalize(snake2camelCase(prop.name)).padEnd(dto.maxFieldNameLength);
121+
const fieldName = capitalize(snake2camelCase(prop.name)).padEnd(dto.maxFieldNameLength)
122122
result += `\t${fieldName} ${prop.type} \`json:"${prop.name}" db:"${prop.name}"\`\n`
123-
});
124-
result += '}\n';
123+
})
124+
result += '}\n'
125125
126-
return result;
126+
return result
127127
}
128128
129-
let globalDtoCounter = 0;
129+
let globalDtoCounter = 0
130130
131-
const dtoCache = {};
131+
const dtoCache = {}
132132
function cacheDto(dto) {
133-
dtoCache[dto.signature] = dto.name;
134-
return dto;
133+
dtoCache[dto.signature] = dto.name
134+
return dto
135135
}
136136
function dtoInCache(dto) {
137137
// always prefer user specified name even when we have a similar DTO in cache
138138
if (dto.hasUserProvidedName) {
139-
return false;
139+
return false
140140
}
141-
return dtoCache.hasOwnProperty(dto.signature);
141+
return dtoCache.hasOwnProperty(dto.signature)
142142
}
143143
144144
const verbs_with_dto = [ 'get', 'post', 'put' ]
@@ -154,32 +154,32 @@ endpoints.forEach(function(endpoint) {
154154
-%>
155155
<%- struct %>
156156
<%
157-
});
158-
});
157+
})
158+
})
159159
-%>
160160
func registerRoutes(r chi.Router, db *sqlx.DB) {
161161
<%
162162
endpoints.forEach(function(endpoint) {
163-
const path = convertPathPlaceholders(endpoint.path);
163+
const path = convertPathPlaceholders(endpoint.path)
164164
165165
endpoint.methods.forEach(function(method) {
166166
if (!method.query) {
167167
// filter out aggregated_queries for a while (see #17)
168168
return
169169
}
170-
const params = extractParamsFromQuery(method.query);
171-
const hasGetOne = method.name === 'get';
172-
const hasGetMany = method.name === 'get_list';
170+
const params = extractParamsFromQuery(method.query)
171+
const hasGetOne = method.name === 'get'
172+
const hasGetMany = method.name === 'get_list'
173173
if (hasGetOne || hasGetMany) {
174-
const dto = query2dto(sqlParser, method);
174+
const dto = query2dto(sqlParser, method)
175175
// LATER: do we really need signature and cache?
176-
const cacheKey = dto ? dto.signature : null;
177-
const dtoName = dtoInCache(dto) ? dtoCache[cacheKey] : dto.name;
176+
const cacheKey = dto ? dto.signature : null
177+
const dtoName = dtoInCache(dto) ? dtoCache[cacheKey] : dto.name
178178
const resultVariableDeclaration = hasGetMany
179179
? `result := []${dtoName}\{\}`
180-
: `var result ${dtoName}`;
180+
: `var result ${dtoName}`
181181
182-
const queryFunction = hasGetOne ? 'Get' : 'Select';
182+
const queryFunction = hasGetOne ? 'Get' : 'Select'
183183
// LATER: handle only particular method (get/post/put)
184184
// LATER: include method/path into an error message
185185
%>
@@ -217,10 +217,10 @@ endpoints.forEach(function(endpoint) {
217217
<%
218218
}
219219
if (method.name === 'post') {
220-
const dto = query2dto(sqlParser, method);
220+
const dto = query2dto(sqlParser, method)
221221
// LATER: do we really need signature and cache?
222-
const cacheKey = dto ? dto.signature : null;
223-
const dataType = dtoInCache(dto) ? dtoCache[cacheKey] : dto.name;
222+
const cacheKey = dto ? dto.signature : null
223+
const dataType = dtoInCache(dto) ? dtoCache[cacheKey] : dto.name
224224
%>
225225
r.Post("<%- path %>", func(w http.ResponseWriter, r *http.Request) {
226226
var body <%- dataType %>
@@ -244,10 +244,10 @@ endpoints.forEach(function(endpoint) {
244244
<%
245245
}
246246
if (method.name === 'put') {
247-
const dto = query2dto(sqlParser, method);
247+
const dto = query2dto(sqlParser, method)
248248
// LATER: do we really need signature and cache?
249-
const cacheKey = dto ? dto.signature : null;
250-
const dataType = dtoInCache(dto) ? dtoCache[cacheKey] : dto.name;
249+
const cacheKey = dto ? dto.signature : null
250+
const dataType = dtoInCache(dto) ? dtoCache[cacheKey] : dto.name
251251
%>
252252
r.Put("<%- path %>", func(w http.ResponseWriter, r *http.Request) {
253253
var body <%- dataType %>
@@ -290,7 +290,7 @@ endpoints.forEach(function(endpoint) {
290290
})
291291
<%
292292
}
293-
});
293+
})
294294
})
295295
%>
296296
}

0 commit comments

Comments
 (0)