Socket
Socket
Sign inDemoInstall

github.com/pseudomuto/protokit

Package Overview
Dependencies
6
Maintainers
0
Alerts
File Explorer

Install Socket

Protect your apps from supply chain attacks

Install

github.com/pseudomuto/protokit

Package protokit is a library that makes it easy to create your own protoc plugins. It has excellent test coverage, and saves you so much time! There are two main things this library provides; a parser for parsing protobuf files into some well-defined structs, and an abstraction to make it simple to write your own protoc plugins. For a quick view of how to get started, see https://godoc.org/github.com/pseudomuto/protokit#example-RunPlugin If you want see/try a working example, check out the examples in https://github.com/pseudomuto/protokit/tree/master/examples.

    v0.2.1

Version published
Maintainers
0

Readme

# protokit

[![CI][github-svg]][github-ci]
[![codecov][codecov-svg]][codecov-url]
[![GoDoc][godoc-svg]][godoc-url]
[![Go Report Card][goreport-svg]][goreport-url]

A starter kit for building protoc-plugins. Rather than write your own, you can just use an existing one.

See the [examples](examples/) directory for uh...examples.

## Getting Started

```golang
package main

import (
    "github.com/golang/protobuf/proto"
    "github.com/golang/protobuf/protoc-gen-go/plugin"
    "github.com/pseudomuto/protokit"
    _ "google.golang.org/genproto/googleapis/api/annotations" // Support (google.api.http) option (from google/api/annotations.proto).

    "log"
)

func main() {
    // all the heavy lifting done for you!
    if err := protokit.RunPlugin(new(plugin)); err != nil {
        log.Fatal(err)
    }
}

// plugin is an implementation of protokit.Plugin
type plugin struct{}

func (p *plugin) Generate(in *plugin_go.CodeGeneratorRequest) (*plugin_go.CodeGeneratorResponse, error) {
    descriptors := protokit.ParseCodeGenRequest(req)

    resp := new(plugin_go.CodeGeneratorResponse)

    for _, d := range descriptors {
        // TODO: YOUR WORK HERE
        fileName := // generate a file name based on d.GetName()
        content := // generate content for the output file

        resp.File = append(resp.File, &plugin_go.CodeGeneratorResponse_File{
            Name:    proto.String(fileName),
            Content: proto.String(content),
        })
    }

    return resp, nil
}
```

Then invoke your plugin via `protoc`. For example (assuming your app is called `thingy`):

`protoc --plugin=protoc-gen-thingy=./thingy -I. --thingy_out=. rpc/*.proto`

[github-svg]: https://github.com/pseudomuto/protokit/actions/workflows/ci.yaml/badge.svg?branch=master
[github-ci]: https://github.com/pseudomuto/protokit/actions/workflows/ci.yaml
[codecov-svg]: https://codecov.io/gh/pseudomuto/protokit/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/pseudomuto/protokit
[godoc-svg]: https://godoc.org/github.com/pseudomuto/protokit?status.svg
[godoc-url]: https://godoc.org/github.com/pseudomuto/protokit
[goreport-svg]: https://goreportcard.com/badge/github.com/pseudomuto/protokit
[goreport-url]: https://goreportcard.com/report/github.com/pseudomuto/protokit

FAQs

Last updated on 15 Feb 2022

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc