-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go.tmpl
80 lines (66 loc) · 2.52 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
{{- 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) -}}
{{- /* 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 core types to JS. */ -}}
{{- $typeMap := dict }}
{{- set $typeMap "null" "nil" -}}
{{- set $typeMap "any" "AnyCodable" -}}
{{- set $typeMap "byte" "String" -}}
{{- 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" "Float" -}}
{{- set $typeMap "float64" "Double" -}}
{{- set $typeMap "string" "String" -}}
{{- set $typeMap "timestamp" "Date" -}}
/* swiftlint:disable */
// {{.SchemaName}} {{.SchemaVersion}} {{.SchemaHash}}
// --
// Code generated by webrpc-gen@{{.WebrpcGenVersion}} with {{.WebrpcTarget}} generator. DO NOT EDIT.
//
// {{.WebrpcGenCommand}}
import AnyCodable
import Foundation
// WebRPC description and code-gen version
public let WebRPCVersion = "{{.WebrpcVersion}}"
// Schema version of your RIDL schema
public let WebRPCSchemaVersion = "{{.SchemaVersion}}"
// Schema hash generated from your RIDL schema
public let WebRPCSchemaHash = "{{.SchemaHash}}"
{{template "types" dict "Types" .Types "Services" .Services "TypeMap" $typeMap}}
{{if $opts.client}}
{{- template "client" dict "Services" .Services "TypeMap" $typeMap}}
{{- template "clientHelpers" dict "WebrpcErrors" .WebrpcErrors "SchemaErrors" .Errors }}
{{- end}}
{{- end}}