generator

package
v0.0.0-...-0d29183 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2023 License: Unlicense Imports: 9 Imported by: 0

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

Types

type TwirpImport

type TwirpImport struct {
	From   string
	Import string
}

type TwirpMethod

type TwirpMethod struct {
	ServiceURL  string
	ServiceName string
	Name        string
	Comment     string
	Input       string
	Output      string
}

type TwirpService

type TwirpService struct {
	ServiceURL string
	Name       string
	Comment    string
	Methods    []*TwirpMethod
}

type TwirpTemplateVariables

type TwirpTemplateVariables struct {
	FileName string
	Services []*TwirpService
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL