pseudomuto/protokit

GitHub: pseudomuto/protokit

protokit 是一个用于在 Go 语言中快速构建 protoc 插件的入门套件,封装了 Protobuf 代码生成请求的底层解析逻辑。

Stars: 81 | Forks: 32

# protokit [![CI](https://static.pigsec.cn/wp-content/uploads/repos/cas/99/993938d8ce5e902ccfb9d6747725c320d855dea3235ed9a304cedf0d94c9321f.svg)][github-ci] [![codecov](https://codecov.io/gh/pseudomuto/protokit/branch/master/graph/badge.svg)][codecov-url] [![GoDoc](https://godoc.org/github.com/pseudomuto/protokit?status.svg)][godoc-url] [![Go Report Card](https://goreportcard.com/badge/github.com/pseudomuto/protokit)][goreport-url] 一个用于构建 protoc-plugins 的入门套件。无需自行编写,您可以直接使用现有的套件。 请查看 [示例](examples/) 目录,嗯……里面就是示例。 ## 快速开始 ``` package main import ( "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/pluginpb" "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 *pluginpb.CodeGeneratorRequest) (*pluginpb.CodeGeneratorResponse, error) { descriptors := protokit.ParseCodeGenRequest(req) resp := new(pluginpb.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, &pluginpb.CodeGeneratorResponse_File{ Name: proto.String(fileName), Content: proto.String(content), }) } return resp, nil } ``` 然后通过 `protoc` 调用您的插件。例如(假设您的应用名为 `thingy`): `protoc --plugin=protoc-gen-thingy=./thingy -I. --thingy_out=. rpc/*.proto`
标签:EVTX分析, Go, Protocol Buffers, protoc插件, Python工具, Ruby工具, SOC Prime, 代码生成, 开发工具, 日志审计, 渗透测试工具, 脚手架