pkg

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0, UNKNOWN, UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultPkgName

func DefaultPkgName(gopkgPath string) (name string)

func GetCallersDirname

func GetCallersDirname() string

Utility for whoever is making a NewPackage manually.

Types

type Package

type Package struct {
	// General info
	GoPkgPath    string
	GoPkgName    string
	DirName      string
	Dependencies []*Package
	Types        []*Type

	// Proto3 info
	P3GoPkgPath  string
	P3PkgName    string
	P3ImportPath string
	P3SchemaFile string
}

amino: immutable TODO

func NewPackage

func NewPackage(gopkgPath string, p3pkgName string, dirName string) *Package

Like amino.RegisterPackage (which is probably what you're looking for unless you are developking on go-amino dependencies), but without global amino registration.

P3GoPkgPath (the import path for go files generated from protoc) are by default set to "<GoPkgPath>/pb", but can be overridden by WithP3GoPkgPath(). You may want to override this for main package, for the subdirectory "pb" doesn't produce a "main/pb" package. See ./proto/example/pacakge.go for such usage.

(This field is needed for improving the performance of encoding and decoding by using protoc generated go code, but is slated to be replaced by native Go generation.)

GoPkgName is by default derived from gopkgPath, but can also be overridden with WithGoPkgName().

P3ImportPath is what is imported in the p3 import spec. Generally this is GoPkgPath + "/" + GoPkgName + ".proto", but packages can override this behavior, and sometimes (e.g. for google.protobuf.Any) it is necessary to provide fixed values. This is not the absolute path to the actual file. That is P3SchemaFile.

Panics if invalid arguments are given, such as slashes in p3pkgName, invalid go pkg paths, or a relative dirName.

func (*Package) CrawlPackages

func (pkg *Package) CrawlPackages(seen map[*Package]struct{}) (res []*Package)

For a given package info, crawl and discover all package infos. Packages already in seen are not returned.

func (*Package) FullNameForType

func (pkg *Package) FullNameForType(rt reflect.Type) string

panics of rt was not registered.

func (*Package) GetAllDependencies

func (pkg *Package) GetAllDependencies() []*Package

func (*Package) GetDependency

func (pkg *Package) GetDependency(gopkg string) (*Package, error)

Finds a dependency package from the gopkg. Well known packages are not known here, so some dependencies may not show up, such as for google.protobuf.Any for any interface fields. For that, use a P3Context.GetPackage().

func (*Package) GetType

func (pkg *Package) GetType(rt reflect.Type) (t Type, ok bool)

Result cannot be modified.

func (*Package) HasFullName

func (pkg *Package) HasFullName(fullname string) (exists bool)

func (*Package) HasName

func (pkg *Package) HasName(name string) (exists bool)

func (*Package) ReflectTypes

func (pkg *Package) ReflectTypes() []reflect.Type

func (*Package) String

func (pkg *Package) String() string

func (*Package) TypeURLForType

func (pkg *Package) TypeURLForType(rt reflect.Type) string

panics of rt (or a pointer to it) was not registered.

func (*Package) WithComments

func (pkg *Package) WithComments(filename string) *Package

Parse the Go code in filename and scan the AST looking for struct doc comments. Find the Type in pkg.Types and set its Comment and FieldComments, which are used by genproto.GenerateProto3MessagePartial to set the Comment in the P3Doc and related P3Field objects.

func (*Package) WithDependencies

func (pkg *Package) WithDependencies(deps ...*Package) *Package

func (*Package) WithGoPkgName

func (pkg *Package) WithGoPkgName(name string) *Package

func (*Package) WithP3GoPkgPath

func (pkg *Package) WithP3GoPkgPath(p3gopkg string) *Package

func (*Package) WithP3ImportPath

func (pkg *Package) WithP3ImportPath(path string) *Package

This path will get imported instead of the default "types.proto" if this package is a dependency. This is not the filesystem path, but the path imported within the proto schema file. The filesystem path is .P3SchemaFile.

func (*Package) WithP3SchemaFile

func (pkg *Package) WithP3SchemaFile(file string) *Package

This file will get imported instead of the default "types.proto" if this package is a dependency.

func (*Package) WithTypes

func (pkg *Package) WithTypes(objs ...interface{}) *Package

type PackageSet

type PackageSet map[string]*Package

e.g. "github.com/tendermint/tendermint/abci/types" ->

&Package{...}

func NewPackageSet

func NewPackageSet() PackageSet

func (PackageSet) Add

func (ps PackageSet) Add(pkg *Package) bool

func (PackageSet) Get

func (ps PackageSet) Get(gopkg string) *Package

func (PackageSet) Has

func (ps PackageSet) Has(gopkg string) bool

type Type

type Type struct {
	Type             reflect.Type
	Name             string            // proto3 name (override)
	PointerPreferred bool              // whether pointer is preferred for decoding interface.
	Comment          string            // optional doc comment for the type
	FieldComments    map[string]string // If not nil, the optional doc comment for each field name
}

func (*Type) FullName

func (t *Type) FullName(pkg *Package) string

Jump to

Keyboard shortcuts

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