Debian Codegraph @

/

debian golang-github-emicklei-proto 1.14.3-1debian golang-github-emicklei-proto-dev gomod github.com/emicklei/proto debiangoinimakemakefilemarkdownshellyaml 63 files · 993 symbols
View dependency graph

Depends on

README (full)

proto

Go Go Report Card GoDoc codecov

Package in Go for parsing Google Protocol Buffers .proto files version 2 + 3, editions

install

go get github.com/emicklei/proto

usage

package main

import (
	"fmt"
	"os"

	"github.com/emicklei/proto"
)

func main() {
	reader, _ := os.Open("test.proto")
	defer reader.Close()

	parser := proto.NewParser(reader)
	definition, _ := parser.Parse()

	proto.Walk(definition,
		proto.WithService(handleService),
		proto.WithMessage(handleMessage))
}

func handleService(s *proto.Service) {
	fmt.Println(s.Name)
}

func handleMessage(m *proto.Message) {
	lister := new(optionLister)
	for _, each := range m.Elements {
		each.Accept(lister)
	}
	fmt.Println(m.Name)
}

type optionLister struct {
	proto.NoopVisitor
}

func (l optionLister) VisitOption(o *proto.Option) {
	fmt.Println(o.Name)
}

validation

Current parser implementation is not completely validating .proto definitions. In many but not all cases, the parser will report syntax errors when reading unexpected charaters or tokens. Use some linting tools or protoc for full validation.

contributions

See proto-contrib for other contributions on top of this package such as protofmt, proto2xsd and proto2gql. protobuf2map is a small package for inspecting serialized protobuf messages using its .proto definition.

© 2017-2025, ernestmicklei.com. MIT License. Contributions welcome.

dir .github/
dir debian/
file .gitignore
file .travis.yml
file CHANGES.md
file LICENSE
file Makefile
file README.md
file comment.go
file comment_test.go
file edition.go
file edition_test.go
file enum.go
file enum_test.go
file extensions.go
file extensions_test.go
file field.go
file field_test.go
file go.mod
file group.go
file group_test.go
file import.go
file import_test.go
file literals.go
file literals_test.go
file message.go
file message_test.go
file noop_visitor.go
file oneof.go
file oneof_test.go
file option.go
file option_test.go
file package.go
file package_test.go
file parent_accessor.go
file parent_test.go
file parser.go
file parser_test.go
file proto.go
file protobuf_test.go
file range.go
file range_test.go
file reserved.go
file reserved_test.go
file service.go
file service_test.go
file syntax.go
file syntax_test.go
file token.go
file token_test.go
file visitor.go
file visitor_test.go
file walk.go
file walk_test.go