forked from webrpc/gen-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go.tmpl
99 lines (84 loc) · 2.74 KB
/
main.go.tmpl
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{{- define "main" -}}
{{- /* Options with default values. */ -}}
{{- $opts := dict -}}
{{- set $opts "pkg" (default .Opts.pkg "proto") -}}
{{- set $opts "client" (ternary (in .Opts.client "" "true") true false) -}}
{{- set $opts "server" (ternary (in .Opts.server "" "true") true false) -}}
{{- /* Print help on -help. */ -}}
{{- if exists .Opts "help" -}}
{{- template "help" $opts -}}
{{- exit 0 -}}
{{- end -}}
{{- /* Print help on unsupported option. */ -}}
{{- range $k, $v := .Opts }}
{{- if not (exists $opts $k) -}}
{{- stderrPrintf "-%v=%q is not supported target option\n\nUsage:\n" $k $v -}}
{{- template "help" $opts -}}
{{- exit 1 -}}
{{- end -}}
{{- end -}}
{{- if ne .WebrpcVersion "v1" -}}
{{- stderrPrintf "%s generator error: unsupported webrpc version %s\n" .WebrpcTarget .WebrpcVersion -}}
{{- exit 1 -}}
{{- end -}}
{{- if not (minVersion .WebrpcGenVersion "v0.7.0") -}}
{{- stderrPrintf "%s generator error: unsupported webrpc-gen version %s, please update\n" .WebrpcTarget .WebrpcGenVersion -}}
{{- exit 1 -}}
{{- end -}}
{{- /* Map webrpc data types to Go. */ -}}
{{- $typeMap := dict }}
{{- set $typeMap "null" "struct{}" -}}
{{- set $typeMap "any" "interface{}" -}}
{{- set $typeMap "byte" "byte" -}}
{{- set $typeMap "bool" "bool" -}}
{{- set $typeMap "uint" "uint" -}}
{{- set $typeMap "uint8" "uint8" -}}
{{- set $typeMap "uint16" "uint16" -}}
{{- set $typeMap "uint32" "uint32" -}}
{{- set $typeMap "uint64" "uint64" -}}
{{- set $typeMap "int" "int" -}}
{{- set $typeMap "int8" "int8" -}}
{{- set $typeMap "int16" "int16" -}}
{{- set $typeMap "int32" "int32" -}}
{{- set $typeMap "int64" "int64" -}}
{{- set $typeMap "float32" "float32" -}}
{{- set $typeMap "float64" "float64" -}}
{{- set $typeMap "string" "string" -}}
{{- set $typeMap "timestamp" "time.Time" -}}
// {{.SchemaName}} {{.SchemaVersion}} {{.SchemaHash}}
// --
// Code generated by webrpc-gen@{{.WebrpcGenVersion}} with {{.WebrpcTarget}} generator. DO NOT EDIT.
//
// {{.WebrpcGenCommand}}
package {{get $opts "pkg"}}
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
"time"
)
// WebRPC description and code-gen version
func WebRPCVersion() string {
return "{{.WebrpcVersion}}"
}
// Schema version of your RIDL schema
func WebRPCSchemaVersion() string {
return "{{.SchemaVersion}}"
}
// Schema hash generated from your RIDL schema
func WebRPCSchemaHash() string {
return "{{.SchemaHash}}"
}
{{ template "types" dict "Services" .Services "Messages" .Messages "TypeMap" $typeMap }}
{{- if $opts.server}}
{{ template "server" dict "Services" .Services "TypeMap" $typeMap }}
{{ end -}}
{{- if $opts.client }}
{{ template "client" dict "Services" .Services "TypeMap" $typeMap }}
{{ end -}}
{{ template "helpers" . }}
{{ end }}