-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go.tmpl
90 lines (76 loc) · 2.67 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" -}}
{{- /* 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 -}}
{{- set $opts "" false -}}
{{- range $_, $service := .Services -}}
{{- range $_, $method := $service.Methods -}}
{{ if eq $method.StreamOutput true -}}
{{- set $opts "streaming" true -}}
{{- end -}}
{{- end -}}
{{- end }}
{{- /* Map webrpc core types to Dart. */ -}}
{{- $typeMap := dict }}
{{- set $typeMap "null" "Null" -}}
{{- set $typeMap "any" "dynamic" -}}
{{- set $typeMap "byte" "int" -}}
{{- 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" "double" -}}
{{- set $typeMap "float64" "double" -}}
{{- set $typeMap "string" "String" -}}
{{- set $typeMap "timestamp" "DateTime" -}}
{{- set $typeMap "map" "Map" -}}
{{- set $typeMap "[]" "List" -}}
// {{.SchemaName}} {{.SchemaVersion}} {{.SchemaHash}}
// --
// Code generated by webrpc-gen@{{.WebrpcGenVersion}} with {{.WebrpcTarget}} generator. DO NOT EDIT.
//
// {{.WebrpcGenCommand}}
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: constant_identifier_names
{{- if $opts.client}}
import 'dart:convert';
import 'dart:async';
import 'package:http/http.dart' as http;
{{- end}}
/// WebRPC description and code-gen version
const webRPCVersion = "{{.WebrpcVersion}}";
/// Schema version of your RIDL schema
const webRPCSchemaVersion = "{{.SchemaVersion}}";
/// Schema hash generated from your RIDL schema
const webRPCSchemaHash = "{{.SchemaHash}}";
{{- if $opts.client}}
{{template "client" dict "Services" .Services "Opts" $opts "TypeMap" $typeMap}}
{{- end}}
{{- if $opts.server}}
{{- stderrPrintf "server generation not yet supported" -}}
{{- exit 1 -}}
{{- end}}
{{template "types" dict "Types" .Types "Services" .Services "TypeMap" $typeMap}}
{{template "errors" dict "WebrpcErrors" .WebrpcErrors "Errors" .Errors}}
{{- end}}