parser

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 9 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrGoPackage = errors.New(`option go_package = "" field is not filled in`)

Functions

func BuildProtoPackageMap added in v1.10.1

func BuildProtoPackageMap(importedProtos []ImportedProto) map[string]ImportedProto

BuildProtoPackageMap returns a map from proto package name to ImportedProto, enabling O(1) lookup of Go package info given a proto type qualifier like "ext".

func CamelCase

func CamelCase(s string) string

CamelCase copy from protobuf, for more information, please see github.com/golang/protobuf@v1.4.2/protoc-gen-go/generator/generator.go:2648

func GetComment

func GetComment(comment *proto.Comment) string

GetComment returns content with prefix //

func GoSanitized

func GoSanitized(s string) string

GoSanitized copy from protobuf, for more information, please see google.golang.org/protobuf@v1.25.0/internal/strs/strings.go:71

func ResolveImports added in v1.10.1

func ResolveImports(src string, protoPaths []string) ([]string, error)

ResolveImports returns the absolute paths of all transitively imported proto files reachable from src, excluding well-known types (google/*). It searches for imported files in protoPaths (equivalent to protoc -I flags). Files that cannot be found in protoPaths are silently skipped so that system-level or well-known protos do not cause errors.

Types

type DefaultProtoParser

type DefaultProtoParser struct{}

DefaultProtoParser types an empty struct

func NewDefaultProtoParser

func NewDefaultProtoParser() *DefaultProtoParser

NewDefaultProtoParser creates a new instance

func (*DefaultProtoParser) Parse

func (p *DefaultProtoParser) Parse(src string, multiple ...bool) (Proto, error)

Parse provides to parse the proto file into a golang structure, which is convenient for subsequent rpc generation and use

type Import

type Import struct {
	*proto.Import
}

Import embeds proto.Import

type ImportedProto added in v1.10.1

type ImportedProto struct {
	// Src is the absolute path to the proto file.
	Src string
	// ProtoPackage is the value of the proto "package" declaration.
	// It is the qualifier used in dotted type references, e.g. "ext" in "ext.ExtReq".
	ProtoPackage string
	// GoPackage is the value of the option go_package field, or the proto
	// package name when go_package is absent.
	GoPackage string
	// PbPackage is the sanitized Go package name derived from GoPackage.
	PbPackage string
}

ImportedProto holds the package information of a transitively imported proto file.

func ParseImportedProtos added in v1.10.1

func ParseImportedProtos(src string, protoPaths []string) ([]ImportedProto, error)

ParseImportedProtos resolves and parses all transitively imported proto files, returning their package information for use in code generation.

type Message

type Message struct {
	*proto.Message
}

Message embeds proto.Message

type Option

type Option struct {
	*proto.Option
}

Option embeds proto.Option

type Package

type Package struct {
	*proto.Package
}

Package defines the protobuf package.

type Proto

type Proto struct {
	Src       string
	Name      string
	Package   Package
	PbPackage string
	GoPackage string
	Import    []Import
	Message   []Message
	Service   Services
	// ImportedProtos holds the metadata for all transitively imported proto files.
	// Populated by the generator before code generation.
	ImportedProtos []ImportedProto
}

Proto describes a proto file,

type RPC

type RPC struct {
	*proto.RPC
}

RPC embeds proto.RPC

type Service

type Service struct {
	*proto.Service
	RPC []*RPC
}

Service describes the rpc service, which is the relevant content after the translation of the proto file

type Services added in v1.4.0

type Services []Service

Services is a slice of Service.

Jump to

Keyboard shortcuts

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