-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go.tmpl
More file actions
95 lines (86 loc) · 3.25 KB
/
Copy pathmain.go.tmpl
File metadata and controls
95 lines (86 loc) · 3.25 KB
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
91
92
93
94
95
{{- 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 "schemaHash" (ternary (eq (default .Opts.schemaHash "true") "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 -}}
{{- /* Streaming is not supported; fail loudly rather than emit broken unary code. */ -}}
{{- range $_, $service := .Services -}}
{{- range $_, $method := $service.Methods -}}
{{- if or $method.StreamInput $method.StreamOutput -}}
{{- stderrPrintf "%s generator error: streaming methods are not supported (%s.%s)\n" $.WebrpcTarget $service.Name $method.Name -}}
{{- exit 1 -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- /* Map webrpc core types to Python. */ -}}
{{- $typeMap := dict -}}
{{- set $typeMap "null" "None" -}}
{{- set $typeMap "any" "Any" -}}
{{- 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" "float" -}}
{{- set $typeMap "float64" "float" -}}
{{- set $typeMap "bigint" "int" -}}
{{- set $typeMap "string" "str" -}}
{{- set $typeMap "timestamp" "datetime" -}}
{{- set $typeMap "map" "dict" -}}
{{- set $typeMap "[]" "list" -}}
{{- /* Resolve schema type aliases to their underlying type for serde. */ -}}
{{- $aliasMap := dict -}}
{{- range $_, $t := .Types -}}
{{- if isAliasType $t -}}
{{- set $aliasMap $t.Name $t.Type -}}
{{- end -}}
{{- end -}}
# {{.SchemaName}} {{.SchemaVersion}}{{if $opts.schemaHash}} {{.SchemaHash}}{{end}}
# --
# Code generated by webrpc-gen@{{.WebrpcGenVersion}} with {{.WebrpcTarget}} generator. DO NOT EDIT.
#
# {{.WebrpcGenCommand}}
from __future__ import annotations
import json
from dataclasses import dataclass
from datetime import datetime, timezone
from enum import Enum
from typing import Any, Optional, Protocol
WEBRPC_HEADER = "Webrpc"
WEBRPC_HEADER_VALUE = "{{.WebrpcHeader}}"
{{if $opts.schemaHash}}
WEBRPC_VERSION = "{{.WebrpcVersion}}"
WEBRPC_SCHEMA_VERSION = "{{.SchemaVersion}}"
WEBRPC_SCHEMA_HASH = "{{.SchemaHash}}"
{{end}}
{{template "types" dict "Types" .Types "TypeMap" $typeMap "AliasMap" $aliasMap}}
{{template "errors" dict "WebrpcErrors" .WebrpcErrors "Errors" .Errors}}
{{template "helpers" dict}}
{{- if $opts.client}}
{{template "client" dict "BasePath" .BasePath "Services" .Services "TypeMap" $typeMap "AliasMap" $aliasMap}}
{{- end}}
{{- if $opts.server}}
{{template "server" dict "BasePath" .BasePath "Services" .Services "TypeMap" $typeMap "AliasMap" $aliasMap}}
{{- end}}
{{- end -}}