Skip to content

Commit 32c316a

Browse files
committed
refactor go templates
1 parent e5949c5 commit 32c316a

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

templates/go/base/params.twig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
params := map[string]interface{}{
2+
{% for parameter in method.parameters.query %}
3+
"{{ parameter.name }}": {{ parameter.name | caseUcfirst }},
4+
{% endfor %}
5+
{% for parameter in method.parameters.body %}
6+
"{{ parameter.name }}": {{ parameter.name | caseUcfirst }},
7+
{% endfor %}
8+
}
9+
10+
headers := map[string]interface{}{
11+
{% for key, header in method.headers %}
12+
"{{ key }}": "{{ header }}",
13+
{% endfor %}
14+
}

templates/go/base/requests/api.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
return srv.client.Call("{{ method.method | caseUpper }}", path, headers, params)

templates/go/services/service.go.twig

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,12 @@ func (srv *{{ service.name | caseUcfirst }}) {{ method.name | caseUcfirst }}({%
3030
{% if method.parameters.path|length > 0 %}
3131
r := strings.NewReplacer({% for parameter in method.parameters.path %}"{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}", {{ parameter.name | caseUcfirst }}{% if not loop.last %}, {% endif %}{% endfor %})
3232
path := r.Replace("{{ method.path }}")
33+
3334
{% else %}
3435
path := "{{ method.path }}"
36+
3537
{% endif %}
36-
37-
params := map[string]interface{}{
38-
{% for parameter in method.parameters.query %}
39-
"{{ parameter.name }}": {{ parameter.name | caseUcfirst }},
40-
{% endfor %}
41-
{% for parameter in method.parameters.body %}
42-
"{{ parameter.name }}": {{ parameter.name | caseUcfirst }},
43-
{% endfor %}
44-
}
45-
46-
headers := map[string]interface{}{
47-
{% for key, header in method.headers %}
48-
"{{ key }}": "{{ header }}",
49-
{% endfor %}
50-
}
51-
return srv.client.Call("{{ method.method | caseUpper }}", path, headers, params)
38+
{{include('go/base/params.twig')}}
39+
{{include('go/base/requests/api.twig')}}
5240
}
5341
{% endfor %}

0 commit comments

Comments
 (0)