protomodfile

package
v0.0.0-...-cf3f34d Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	ProtoModFilename string = "proto.mod"
)
View Source
const ProtoSumFilename string = "proto.sum"

Variables

View Source
var ErrNotAFile = errors.New("not a normal file")

Functions

func Base

func Base(require *modfile.Require) string

Base returns the value of the `base=some/dir` trailing comment on the require line. If there is no base property, "" is returned.

Base is used to correct the proto file base dir for any dependencies that don't have their own proto.mod file.

Example
// typically got via ProtoModFile.Require
require := newRequire("my/dep v1.0.0 // base=protos")
fmt.Println(Base(require))
Output:

protos

func Find

func Find(startingFromDir string) (string, error)

Find finds the path of a proto.mod file in the provided directory or any parent directory

func FindSumFile

func FindSumFile(protoModPath string) (string, error)

FindSumFile will attempt to locate a proto.sum file alongside the given proto.mod file. Will error if the file could not be found, or if it could not be accessed.

Use `errors.Is(os.ErrNotExist, ...)` to check if this failed because the file was absent. Use `errors.Is(ErrNotAFile)` to check if this failed because a directory was found.

func SetBase

func SetBase(require *modfile.Require, base string)

SetBase updates require with a trailing comment containing base=base. If base is "" then this removes that section of the comment, potentially removing the entire comment.

Types

type ProtoModFile

type ProtoModFile modfile.File

func Parse

func Parse(path string, contents []byte) (*ProtoModFile, error)

func ParseFromFile

func ParseFromFile(path string) (*ProtoModFile, error)

func (*ProtoModFile) Base

func (f *ProtoModFile) Base() string

Base returns the value of the `base=some/dir` trailing comment on the module line. If there is no base property, "" is returned.

Base is used when the location of the proto.mod file doesn't accurately represent the base dir of the proto files in the given module.

Example

fmt.Println(Base(module my/dep // base=my/dir"))
// Output: my/dir

func (*ProtoModFile) BaseMod

func (f *ProtoModFile) BaseMod(mod module.Version) (base string, found bool)

BaseMod calls Base on the f.Require that has a Require.Mod == mod.

func (*ProtoModFile) SetBase

func (f *ProtoModFile) SetBase(base string)

SetBase updates the mod file with a trailing comment containing base=base. If base is "" then this removes that section of the comment, potentially removing the entire comment.

type ProtoSumEntry

type ProtoSumEntry struct {
	// ModulePath is the fully-qualified path of the module in question.
	// The proto.mod file can be found in the directory identified by this path.
	// e.g. github.com/foo/bar
	ModulePath string
	// Version is the version number of this module for which the hash has been computed.
	// As in Go, it always starts with a vX.Y.Z, which follows semver, and may be followed
	// by extra release information, for example a commit date and ID.
	// It might end with the special string /proto.mod, which signifies that the hash
	// in this entry is computed over just the proto.mod file, and not all the other files in
	// the module.
	Version string
	// HashAlg is the algorithm used to compute the hash. Should always be "h1", as this
	// is the only hash algorithm currently supported.
	HashAlg string
	// Hash is bytes of the raw decoded hash. Within the file itself, it is stored as a Base64-encoded
	// string. It's simply the output of the hash function identified by HashAlg.
	Hash []byte
}

ProtoSumEntry represents the information contained on one line of a proto.sum file. As protomod is closely modelled on Go's module system, the syntax of this file is the same as the go.sum file.

func ParseSumEntry

func ParseSumEntry(line string) (ProtoSumEntry, error)

ParseSumEntry parses a single line of a sum file. All sum files are simply a list of such lines.

func ParseSumFile

func ParseSumFile(data []byte) ([]ProtoSumEntry, error)

ParseSumFile will parse a sum file from its contents. Errors if the file syntax is invalid.

func ParseSumFileFromFile

func ParseSumFileFromFile(path string) ([]ProtoSumEntry, error)

ParseSumFileFromFile will read a sum file from the given path and attempt to parse it. Can fail if the file read fails, or if the file's syntax is invalid.

func (*ProtoSumEntry) IsProtoSumOnly

func (entry *ProtoSumEntry) IsProtoSumOnly() bool

IsProtoSumOnly returns true if the version contains the special /proto.mod suffix

func (*ProtoSumEntry) ModuleVersion

func (entry *ProtoSumEntry) ModuleVersion() string

ModuleVersion returns Version, but with the /proto.mod suffix removed, if it exists.

Jump to

Keyboard shortcuts

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