-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go.tmpl
78 lines (67 loc) · 2.68 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
{{- define "main" -}}
{{- /* Options with default values. */ -}}
{{- $opts := dict -}}
{{- set $opts "client" (ternary (in .Opts.client "" "true") true false) -}}
{{- set $opts "server" (ternary (in .Opts.server "" "true") true false) -}}
{{- set $opts "exports" (ternary (in .Opts.exports "false") false true) -}}
{{- /* 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.9.0") -}}
{{- stderrPrintf "%s generator error: unsupported webrpc-gen version %s, please update\n" .WebrpcTarget .WebrpcGenVersion -}}
{{- exit 1 -}}
{{- end -}}
{{- /* Map webrpc core types to JS. */ -}}
{{- $typeMap := dict }}
{{- set $typeMap "null" "null" -}}
{{- set $typeMap "any" "any" -}}
{{- set $typeMap "byte" "string" -}}
{{- set $typeMap "bool" "boolean" -}}
{{- set $typeMap "uint" "number" -}}
{{- set $typeMap "uint8" "number" -}}
{{- set $typeMap "uint16" "number" -}}
{{- set $typeMap "uint32" "number" -}}
{{- set $typeMap "uint64" "number" -}}
{{- set $typeMap "int" "number" -}}
{{- set $typeMap "int8" "number" -}}
{{- set $typeMap "int16" "number" -}}
{{- set $typeMap "int32" "number" -}}
{{- set $typeMap "int64" "number" -}}
{{- set $typeMap "float32" "number" -}}
{{- set $typeMap "float64" "number" -}}
{{- set $typeMap "string" "string" -}}
{{- set $typeMap "timestamp" "string" -}}
// {{.SchemaName}} {{.SchemaVersion}} {{.SchemaHash}}
// --
// Code generated by webrpc-gen@{{.WebrpcGenVersion}} with {{.WebrpcTarget}} generator. DO NOT EDIT.
//
// {{.WebrpcGenCommand}}
// WebRPC description and code-gen version
{{if $opts.exports}}export {{end}}const WebRPCVersion = "{{.WebrpcVersion}}"
// Schema version of your RIDL schema
{{if $opts.exports}}export {{end}}const WebRPCSchemaVersion = "{{.SchemaVersion}}"
// Schema hash generated from your RIDL schema
{{if $opts.exports}}export {{end}}const WebRPCSchemaHash = "{{.SchemaHash}}"
{{template "types" dict "Services" .Services "Types" .Types "Opts" $opts}}
{{- if $opts.client}}
{{template "client" dict "Services" .Services "Opts" $opts}}
{{template "client_helpers" .}}
{{- end}}
{{- if $opts.server}}
{{template "server" dict "Services" .Services "Opts" $opts "TypeMap" $typeMap}}
{{- end}}
{{- end}}