gengrpc

package module
v0.0.0-...-29ef4e7 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: MIT Imports: 10 Imported by: 0

README

gengrpc - Generate gRPC

Copyright (c) 2022, 2023, Geert JM Vanderkelen

gengrpc is a package and command line tool to generate gRPC code from Protocol Buffer contract files. It is based on the tool found in the project pxmysql but focusing on getting the contracts through Go packages. The idea is to eventually use genrpc in pxmysql, merging both functionalities.

Quick start

This project wraps around the protoc tool. You will need to install this first. Actually, you can use protoc directly, but it can become painful with lots of contract files (hence this package).

You have:

  • contract files (*.proto) in a shared Go package, for example, example.com/golistic/shared and files are located in that repository under grpc
  • you have another project example.com/golistic/eventing which needs to generate using the contract files found in the shared project
  • you want the generate code in the folder internal/grpc

Using the above example, you can the execute the following:

$ gorpc --module example.com/golistic/eventing \
 --source example.com/golistic/shared \
 --source-path grpc \
 --dest-path internal/grpc

The --source-path flag is optional. If not provided, all .proto files will be included.

The source-package must be loaded through Go modules. It works using Go workspaces.

License

Distributed under the MIT license. See LICENSE.md for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(module string, source sourcer, destPath string) error

Generate will generate Go code by compiling .proto files found within the sourcePackages in the directory sourcePath. The resulting files will be source in directory destPath.

Types

type GoPackage

type GoPackage struct {
	// contains filtered or unexported fields
}

func NewGoPackage

func NewGoPackage(packageName, pathInPackage string) (*GoPackage, error)

func (*GoPackage) ContractPath

func (gp *GoPackage) ContractPath() string

func (*GoPackage) Contracts

func (gp *GoPackage) Contracts() ([]string, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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