-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.go.tmpl
More file actions
46 lines (43 loc) · 1.1 KB
/
client.go.tmpl
File metadata and controls
46 lines (43 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{{define "client"}}
{{- $basepath := .BasePath -}}
{{- $services := .Services -}}
{{- $opts := .Opts -}}
{{- if $services }}
//
// Client
//
{{ range $services }}
{{if $opts.exports}}export {{end}}class {{.Name}} {
constructor(hostname, fetch) {
this.path = '{{$basepath}}{{.Name}}/'
this.hostname = hostname
this.fetch = (input, init) => fetch(input, init)
}
url(name) {
return this.hostname + this.path + name
}
{{range .Methods}}
{{firstLetterToLower .Name}} = ({{if len .Inputs}}args, {{end}}headers) => {
return this.fetch(
this.url('{{.Name}}'),
{{- if .Inputs | len}}
createHTTPRequest(args, headers)
{{- else}}
createHTTPRequest({}, headers)
{{- end}}
).then((res) => {
return buildResponse(res).then(_data => {
return {
{{- $outputsCount := .Outputs|len -}}
{{- range $i, $output := .Outputs}}
{{if gt $i 0}}, {{end}}{{$output.Name}}: {{if isStructType $output.Type}}new {{$output.Type}}{{end}}(_data.{{$output.Name}})
{{- end}}
}
})
})
}
{{end}}
}
{{end -}}
{{end -}}
{{end}}