Documentation
¶
Index ¶
- Constants
- Variables
- func Commit(cfg Config) (io.Reader, error)
- func HandleReport(report *Report, w io.Writer, err error) (int, error)
- func Init(cfg Config) (io.Reader, error)
- func SetDebug(status bool)
- func SetStrict(mode bool)
- type Config
- type Definition
- type Entry
- type Enum
- type EnumField
- type Field
- type Import
- type Map
- type Message
- type Option
- type Package
- type ProtoFile
- type Protolock
- type Protopath
- type RPC
- type Report
- type Rule
- type RuleFunc
- type Service
- type Warning
- func NoChangingFieldIDs(cur, upd Protolock) ([]Warning, bool)
- func NoChangingFieldNames(cur, upd Protolock) ([]Warning, bool)
- func NoChangingFieldTypes(cur, upd Protolock) ([]Warning, bool)
- func NoChangingRPCSignature(cur, upd Protolock) ([]Warning, bool)
- func NoMovingExistingFieldsIntoOrOutOfOneof(cur, upd Protolock) ([]Warning, bool)
- func NoRemovingFieldsWithoutReserve(cur, upd Protolock) ([]Warning, bool)
- func NoRemovingRPCs(cur, upd Protolock) ([]Warning, bool)
- func NoRemovingReservedFields(cur, upd Protolock) ([]Warning, bool)
- func NoUsingReservedFields(cur, upd Protolock) ([]Warning, bool)
Constants ¶
const ( // FileSep is the string representation of the OS-specific path separator. FileSep = string(filepath.Separator) // ProtoSep is an OS-ambiguous path separator to encode into the proto.lock // file. Use OsPath and ProtoPath funcs to convert. ProtoSep = ":/:" )
const (
// CommentSkip tells the parse step to skip the comparable entity.
CommentSkip = "@protolock:skip"
)
const LockFileName = "proto.lock"
Variables ¶
var ErrOutOfDate = errors.New("proto.lock file is not up-to-date with source")
ErrOutOfDate indicates that the locked definitions are ahead or behind of the source proto definitions within the tree.
var ( // ErrSkipEntry indicates that the CommentSkip hint was found. ErrSkipEntry = errors.New("protolock: skip entry hint encountered") )
var (
ErrWarningsFound = errors.New("comparison found one or more warnings")
)
var ( // Rules provides a complete list of all funcs to be run to compare // a set of Protolocks. This list should be updated as new RuleFunc's // are added to this package. Rules = []Rule{ { Name: "NoUsingReservedFields", Func: NoUsingReservedFields, }, { Name: "NoRemovingReservedFields", Func: NoRemovingReservedFields, }, { Name: "NoRemovingFieldsWithoutReserve", Func: NoRemovingFieldsWithoutReserve, }, { Name: "NoChangingFieldIDs", Func: NoChangingFieldIDs, }, { Name: "NoChangingFieldTypes", Func: NoChangingFieldTypes, }, { Name: "NoChangingFieldNames", Func: NoChangingFieldNames, }, { Name: "NoRemovingRPCs", Func: NoRemovingRPCs, }, { Name: "NoChangingRPCSignature", Func: NoChangingRPCSignature, }, { Name: "NoMovingExistingFieldsIntoOrOutOfOneof", Func: NoMovingExistingFieldsIntoOrOutOfOneof, }, } )
Functions ¶
func Commit ¶
Commit will return an io.Reader with the lock representation data for caller to use as needed.
func HandleReport ¶ added in v0.11.0
HandleReport checks a report for warnigs and writes warnings to an io.Writer. The returned int (an exit code) is 1 if warnings are encountered.
func Init ¶
Init will return an io.Reader with the lock representation data for caller to use as needed.
Types ¶
type Config ¶ added in v0.10.0
func (*Config) LockFileExists ¶ added in v0.10.0
func (*Config) LockFilePath ¶ added in v0.10.0
type Definition ¶
type Entry ¶
type Enum ¶
type Enum struct {
Name string `json:"name,omitempty"`
EnumFields []EnumField `json:"enum_fields,omitempty"`
ReservedIDs []int `json:"reserved_ids,omitempty"`
ReservedNames []string `json:"reserved_names,omitempty"`
AllowAlias bool `json:"allow_alias,omitempty"`
Options []Option `json:"options,omitempty"`
}
type Field ¶
type Field struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
IsRepeated bool `json:"is_repeated,omitempty"`
IsOptional bool `json:"optional,omitempty"`
IsRequired bool `json:"required,omitempty"`
Options []Option `json:"options,omitempty"`
OneofParent string `json:"oneof_parent,omitempty"`
}
type Message ¶
type Message struct {
Name string `json:"name,omitempty"`
Fields []Field `json:"fields,omitempty"`
Maps []Map `json:"maps,omitempty"`
ReservedIDs []int `json:"reserved_ids,omitempty"`
ReservedNames []string `json:"reserved_names,omitempty"`
Filepath Protopath `json:"filepath,omitempty"`
Messages []Message `json:"messages,omitempty"`
Options []Option `json:"options,omitempty"`
}
type Protolock ¶
type Protolock struct {
Definitions []Definition `json:"definitions,omitempty"`
}
func FromReader ¶ added in v0.11.2
FromReader unmarshals a proto.lock file into a Protolock struct.
type Protopath ¶ added in v0.9.0
type Protopath string
Protopath is a type to assist in OS filepath transformations
type Report ¶
type Report struct {
Current Protolock `json:"current,omitempty"`
Updated Protolock `json:"updated,omitempty"`
Warnings []Warning `json:"warnings,omitempty"`
}
type RuleFunc ¶
RuleFunc defines the common signature for a function which can compare Protolock states and determine if issues exist.
type Warning ¶
type Warning struct {
Filepath Protopath `json:"filepath,omitempty"`
Message string `json:"message,omitempty"`
RuleName string `json:"rulename,omitempty"`
}
func NoChangingFieldIDs ¶
NoChangingFieldIDs compares the current vs. updated Protolock definitions and will return a list of warnings if any field ID number has been changed.
func NoChangingFieldNames ¶
NoChangingFieldNames compares the current vs. updated Protolock definitions and will return a list of warnings if any message's previous fields have been renamed. This rule is only enforced when strict mode is enabled.
func NoChangingFieldTypes ¶
NoChangingFieldTypes compares the current vs. updated Protolock definitions and will return a list of warnings if any field type has been changed.
func NoChangingRPCSignature ¶
NoChangingRPCSignature compares the current vs. updated Protolock definitions and will return a list of warnings if any RPC signature has been changed while using the same name.
func NoMovingExistingFieldsIntoOrOutOfOneof ¶ added in v0.17.0
Existing fields must not be moved into or out of a oneof. This is a backwards-incompatible change in the Go protobuf stubs. per https://google.aip.dev/180#moving-into-oneofs
func NoRemovingFieldsWithoutReserve ¶
NoRemovingFieldsWithoutReserve compares the current vs. updated Protolock definitions and will return a list of warnings if any field has been removed without a corresponding reservation of that field name or ID.
func NoRemovingRPCs ¶
NoRemovingRPCs compares the current vs. updated Protolock definitions and will return a list of warnings if any RPCs provided by a Service have been removed. This rule is only enforced when strict mode is enabled.
func NoRemovingReservedFields ¶
NoRemovingReservedFields compares the current vs. updated Protolock definitions and will return a list of warnings if any reserved field has been removed. This rule is only enforced when strict mode is enabled.
func NoUsingReservedFields ¶
NoUsingReservedFields compares the current vs. updated Protolock definitions and will return a list of warnings if any message's previously reserved fields or IDs are now being used as part of the same message.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
protolock
command
|
|
|
plugin-samples
|
|
|
plugin-sample
command
|
|
|
plugin-sample-error
command
|
|
|
plugin-sample-wasm
module
|