twirpex

package module
v0.0.0-...-369160a Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

README

Twirp Extensions

Generates some useful code

rpc_service.twirpex.go

package pkg

import (
    "github.com/albenik/twirpex"
)

func NewRPCServiceServerEx(svc rpcService, opts ...interface{}) twirpex.TwirpServer {
    return NewRPCServiceServer(svc, opts...).(*rpcService)
}

func (*rpcServiceServer) TwirpServiceMeta() *twirpex.ServiceMeta {
    return &twirpex.ServiceMeta{
        PackageName:     "protobuf.package.v1",
        ServiceName:     "RPCService",
        ServiceFullName: "protobuf.package.v1.RPCService",
        MethodsNames: []string{
            "Foo",
            "Bar",
        },
    }
}

Install

go install github.com/albenik/twirpex/cmd/protoc-gen-twirpex@latest

Use

With protoc

protoc -twirpex_out=path/to/doc/folder -twirpex_opt=paths=source_relative twirp/service/v1/service.proto

With buf https://buf.build

buf.gen.yaml:

version: v1
plugins:
  - name: twirpex
    out: path/to/doc/folder
    opt: paths=source_relative

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ServiceMeta

type ServiceMeta struct {
	PackageName     string
	ServiceName     string
	ServiceFullName string
	MethodsNames    []string
}

type TwirpServer

type TwirpServer interface {
	http.Handler

	// ServiceDescriptor returns gzipped bytes describing the .proto file that
	// this service was generated from. Once unzipped, the bytes can be
	// unmarshalled as a
	// google.golang.org/protobuf/types/descriptorpb.FileDescriptorProto.
	//
	// The returned integer is the index of this particular service within that
	// FileDescriptorProto's 'Service' slice of ServiceDescriptorProtos. This is a
	// low-level field, expected to be used for reflection.
	ServiceDescriptor() ([]byte, int)

	// ProtocGenTwirpVersion is the semantic version string of the version of
	// twirp used to generate this file.
	ProtocGenTwirpVersion() string

	// PathPrefix returns the HTTP URL path prefix for all methods handled by this
	// service. This can be used with an HTTP mux to route Twirp requests.
	// The path prefix is in the form: "/<prefix>/<package>.<Service>/"
	// that is, everything in a Twirp route except for the <Method> at the end.
	PathPrefix() string

	TwirpServiceMeta() *ServiceMeta
}

TwirpServer is the interface generated server structs will support: they're HTTP handlers with additional methods for accessing metadata about the service. Those accessors are a low-level API for building reflection tools. Most people can think of TwirpServers as just http.Handlers.

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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