-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go.tmpl
83 lines (70 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
{{- 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) -}}
{{- /* Allow to pass custom package name. */ -}}
{{- if (exists .Opts "packageName") -}}
{{- set $opts "packageName" (index .Opts "packageName") -}}
{{ else }}
{{- set $opts "packageName" "io.webrpc.client" -}}
{{- end -}}
{{- /* 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.14.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" "UInt" -}}
{{- set $typeMap "uint8" "UByte" -}}
{{- set $typeMap "uint16" "UShort" -}}
{{- set $typeMap "uint32" "UInt" -}}
{{- set $typeMap "uint64" "ULong" -}}
{{- set $typeMap "int" "Int" -}}
{{- set $typeMap "int8" "Byte" -}}
{{- set $typeMap "int16" "Short" -}}
{{- set $typeMap "int32" "Int" -}}
{{- set $typeMap "int64" "Long" -}}
{{- set $typeMap "float32" "Float" -}}
{{- set $typeMap "float64" "Double" -}}
{{- set $typeMap "string" "String" -}}
{{- set $typeMap "timestamp" "OffsetDateTime" -}}
{{template "imports" dict "Opts" $opts}}
// {{.SchemaName}} {{.SchemaVersion}} {{.SchemaHash}}
// --
// Code generated by webrpc-gen@{{.WebrpcGenVersion}} with {{.WebrpcTarget}} generator. DO NOT EDIT.
//
// {{.WebrpcGenCommand}}
// WebRPC description and code-gen version
const val WEBRPC_VERSION = "{{.WebrpcVersion}}"
// Schema version of your RIDL schema
const val WEBRPC_SCHEMA_VERSION = "{{.SchemaVersion}}"
// Schema hash generated from your RIDL schema
const val WEBRPC_SCHEMA_HASH = "{{.SchemaHash}}"
{{template "types" dict "Types" .Types "Services" .Services "TypeMap" $typeMap}}
{{if $opts.client}}
{{- template "client" dict "Types" .Types "Services" .Services "TypeMap" $typeMap}}
{{- template "clientHelpers" dict "WebrpcErrors" .WebrpcErrors "SchemaErrors" .Errors }}
{{- end}}
{{- end}}