protoanalysis

package
v0.0.0-...-d298eb8 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package protoanalysis provides a toolset for analyzing proto files and packages.

Index

Constants

This section is empty.

Variables

View Source
var ErrImportNotFound = errors.New("proto import not found")

ErrImportNotFound returned when proto file import cannot be found.

Functions

func HasMessages

func HasMessages(ctx context.Context, path string, names ...string) error

HasMessages checks if the proto package under path contains messages with given names.

func IsImported

func IsImported(path string, dependencies ...string) error

IsImported checks if the proto package under path imports list of dependencies.

Types

type Cache

type Cache map[string]Packages // proto dir path-proto packages pair.

func NewCache

func NewCache() Cache

type File

type File struct {
	// Path of the file.
	Path string

	// Dependencies is a list of imported .proto files in this package.
	Dependencies []string
}

func ParseFile

func ParseFile(path string) (File, error)

ParseFile parses a proto file at path.

type Files

type Files []File

func (Files) Paths

func (f Files) Paths() []string

type HTTPRule

type HTTPRule struct {
	// Params is a list of parameters defined in the http endpoint itself.
	Params []string

	// HasQuery indicates if there is a request query.
	HasQuery bool

	// HasBody indicates if there is a request payload.
	HasBody bool
}

HTTPRule keeps info about a configured http rule of an RPC func.

type Message

type Message struct {
	// Name of the message.
	Name string

	// Path of the file where message is defined at.
	Path string

	// HighestFieldNumber is the highest field number among fields of the message
	// This allows to determine new field number when writing to proto message
	HighestFieldNumber int

	// Fields contains message's field names and types
	Fields map[string]string
}

Message represents a proto message.

type Package

type Package struct {
	// Name of the proto pkg.
	Name string

	// Path of the package in the fs.
	Path string

	// Files is a list of .proto files in the package.
	Files Files

	// GoImportName is the go package name of proto package.
	GoImportName string

	// Messages is a list of proto messages defined in the package.
	Messages []Message

	// Services is a list of RPC services.
	Services []Service
}

Package represents a proto pkg.

func (Package) GoImportPath

func (p Package) GoImportPath() string

GoImportPath retrieves the Go import path.

func (Package) MessageByName

func (p Package) MessageByName(name string) (Message, error)

MessageByName finds a message by its name inside Package.

type Packages

type Packages []Package

func Parse

func Parse(ctx context.Context, cache Cache, path string) (Packages, error)

Parse parses proto packages by finding them with given glob pattern.

func (Packages) Files

func (p Packages) Files() Files

type RPCFunc

type RPCFunc struct {
	// Name of the RPC func.
	Name string

	// RequestType is the request type of RPC func.
	RequestType string

	// ReturnsType is the response type of RPC func.
	ReturnsType string

	// HTTPRules keeps info about http rules of an RPC func.
	// spec:
	//   https://github.com/googleapis/googleapis/blob/master/google/api/http.proto.
	HTTPRules []HTTPRule

	// Paginated indicates that the RPC function is using pagination.
	Paginated bool
}

RPCFunc is an RPC func.

type Service

type Service struct {
	// Name of the services.
	Name string

	// RPC is a list of RPC funcs of the service.
	RPCFuncs []RPCFunc
}

Service is an RPC service.

Directories

Path Synopsis
Package protoutil wraps proto structs to allow easier creation, protobuf lang is small enough to easily allow this.
Package protoutil wraps proto structs to allow easier creation, protobuf lang is small enough to easily allow this.

Jump to

Keyboard shortcuts

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