-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go.tmpl
90 lines (74 loc) · 3.07 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
{{- define "main" -}}
{{- $opts := dict -}}
{{- set $opts "client" (ternary (in .Opts.client "" "true") true false) -}}
{{- set $opts "server" (ternary (not (eq (get .Opts "server") "")) true false) -}}
{{- if exists .Opts "help" -}}
{{- template "help" $opts -}}
{{- exit 0 -}}
{{- end -}}
{{- range $k, $v := .Opts }}
{{- if not (exists $opts $k) -}}
{{- stderrPrintf "-%s=%s is not a 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 -}}
{{- $typeMap := dict }}
{{- set $typeMap "null" "None" -}}
{{- set $typeMap "any" "Any" -}}
{{- set $typeMap "byte" "str" -}}
{{- set $typeMap "bool" "bool" -}}
{{- set $typeMap "uint" "int" -}}
{{- set $typeMap "uint8" "int" -}}
{{- set $typeMap "uint16" "int" -}}
{{- set $typeMap "uint32" "int" -}}
{{- set $typeMap "uint64" "int" -}}
{{- set $typeMap "int" "int" -}}
{{- set $typeMap "int8" "int" -}}
{{- set $typeMap "int16" "int" -}}
{{- set $typeMap "int32" "int" -}}
{{- set $typeMap "int64" "int" -}}
{{- set $typeMap "float32" "float" -}}
{{- set $typeMap "float64" "float" -}}
{{- set $typeMap "string" "str" -}}
{{- set $typeMap "timestamp" "str" -}}
{{- set $typeMap "double" "float" -}}
# --
# Code generated by webrpc-gen@{{.WebrpcGenVersion}} with {{.WebrpcTarget}} generator. DO NOT EDIT.
# WebRPC description and code-gen version
WebRPCVersion = "{{.WebrpcVersion}}"
# Schema version of your RIDL schema
WebRPCSchemaVersion = "{{.SchemaVersion}}"
# Schema hash generated from your RIDL schema
WebRPCSchemaHash = "{{.SchemaHash}}"
{{template "types" dict "Types" .Types "Services" .Services "TypeMap" $typeMap}}
{{ if $opts.client}}
{{template "client" dict "Services" .Services "TypeMap" $typeMap}}
{{template "client_helpers" dict "WebrpcErrors" .WebrpcErrors "SchemaErrors" .Errors }}
{{ end}}
{{- if $opts.server}}
{{- $serverOption := get .Opts "server" -}}
{{- if or (eq $serverOption "flask") (eq $serverOption "true") }}
{{- template "flask" dict "Services" .Services "Opts" $opts "TypeMap" $typeMap }}
{{- template "server_helpers" dict "Messages" .Types "TypeMap" $typeMap}}
{{- else if eq $serverOption "django" }}
{{- template "django" dict "Services" .Services "Opts" $opts "TypeMap" $typeMap }}
{{- template "server_helpers" dict "Messages" .Types "TypeMap" $typeMap}}
{{- else if eq $serverOption "fastapi" }}
{{- template "fastapi" dict "Services" .Services "Opts" $opts "TypeMap" $typeMap }}
{{- template "server_helpers" dict "Messages" .Types "TypeMap" $typeMap}}
{{- else}}
{{- stderrPrintf "Unsupported server option: %q\n\nUsage:\n" $opts.server -}}
{{- template "help" $opts -}}
{{- exit 1 -}}
{{- end }}
{{- end }}
{{- end }}