Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var TwirpTemplate = template.Must(template.New("TwirpTemplate").Parse(`# -*- coding: utf-8 -*-
# Generated by https://github.com/verloop/twirpy/protoc-gen-twirpy. DO NOT EDIT!
# source: {{.FileName}}
from google.protobuf import symbol_database as _symbol_database
from twirp.base import Endpoint
from twirp.server import TwirpServer
from twirp.client import TwirpClient
_sym_db = _symbol_database.Default()
{{range .Services}}
class {{.Name}}Server(TwirpServer):
def __init__(self, *args, service, server_path_prefix="/twirp"):
super().__init__(service=service)
self._prefix = F"{server_path_prefix}/{{.ServiceURL}}"
self._endpoints = { {{- range .Methods }}
"{{.Name}}": Endpoint(
service_name="{{.ServiceName}}",
name="{{.Name}}",
function=getattr(service, "{{.Name}}"),
input=_sym_db.GetSymbol("{{.Input}}"),
output=_sym_db.GetSymbol("{{.Output}}"),
),{{- end }}
}
class {{.Name}}Client(TwirpClient):
{{range .Methods}}
def {{.Name}}(self, *args, ctx, request, server_path_prefix="/twirp", **kwargs):
return self._make_request(
url=F"{server_path_prefix}/{{.ServiceURL}}/{{.Name}}",
ctx=ctx,
request=request,
response_obj=_sym_db.GetSymbol("{{.Output}}"),
**kwargs,
)
{{end}}{{end}}`))
TwirpTemplate - Template for twirp server and client
Functions ¶
func Generate ¶
func Generate(r *plugin.CodeGeneratorRequest) *plugin.CodeGeneratorResponse
func GenerateTwirpFile ¶
func GenerateTwirpFile(fd *descriptor.FileDescriptorProto) (*plugin.CodeGeneratorResponse_File, error)
Types ¶
type TwirpImport ¶
type TwirpMethod ¶
type TwirpService ¶
type TwirpService struct { ServiceURL string Name string Comment string Methods []*TwirpMethod }
type TwirpTemplateVariables ¶
type TwirpTemplateVariables struct { FileName string Services []*TwirpService }
Click to show internal directories.
Click to hide internal directories.