Categorygithub.com/amery/protogen
repository
0.3.11
Repository: https://github.com/amery/protogen.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# 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)
}