protogen

module
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: MIT

README

protogen

Go Reference Go Report Card

protogen is a Go library to write proto code generators for any language.

Setting protogen up

The recommended way is to begin with a protogen.Options instance and run it against a handler.

opts := &protogen.Options{
    // ...
}

err := opts.Run(func (gen *protogen.Plugin) error {
    // ...
})
if err != nil {
    log.Fatal(err)
}

In this scenario the CodeGeneratorRequest will be parsed from opts.Stdin and the CodeGeneratorResponse will be written to opts.Stdout as expected by protoc.

For testing, you can provide a preparsed CodeGeneratorRequest manually.

opts := &protogen.Options{
    // ...
}

req := &pluginpb.CodeGeneratorRequest{
    // ...
}

gen, err := opts.New(req)
if err != nil {
    log.Fatal(err)
}

err = h(gen)
if err != nil {
    log.Fatal(err)
}

// extract the `pluginpb.CodeGEneratorResponse` object
resp := gen.Response()
// or write it to opts.Stdout
_, err = gen.Write()
if err != nil {
    log.Fatal(err)
}

Directories

Path Synopsis
cmd
protoc-gen-dump
Package main implements a pluginpb.CodeGeneratorRequest dumper
Package main implements a pluginpb.CodeGeneratorRequest dumper
pkg
protogen
Package protogen assists on making Go protoc plugins for any language
Package protogen assists on making Go protoc plugins for any language
protogen/plugin
Package plugin assists at building the plugin's main
Package plugin assists at building the plugin's main

Jump to

Keyboard shortcuts

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