Here is the .proto
file I used:
pkg/apis/workflow/v1alpha1/generated.proto
syntax = 'proto2';
package go-server.com.argo-new.pkg.apis.workflow.v1alpha1;
import "k8s.io/api/core/v1/generated.proto";
import "k8s.io/api/policy/v1beta1/generated.proto";
import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto";
import "k8s.io/apimachinery/pkg/runtime/generated.proto";
import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto";
// Package-wide variables from generator "generated".
option go_package = "v1alpha1";
// ArchiveStrategy describes how to archive files/directory when saving artifacts
message ArchiveStrategy {
optional TarStrategy tar = 1;
optional NoneStrategy none = 2;
}
When I tried to compile:
protoc -I /usr/local/include -I . -I ./vendor -I /root/go/src \
-I /root/go/pkg/mod/github.com/gogo/protobuf@v1.3.1/gogoproto \
-I /root/go/pkg/mod/github.com/grpc-ecosystem/grpc-gateway@v1.12.2/third_party/googleapis \
--include_imports --gogofast_out=plugins=grpc:/root/go/src \
--grpc-gateway_out=logtostderr=true:/root/go/src \
--swagger_out=logtostderr=true,fqn_for_swagger_name=true:. \
pkg/apis/workflow/v1alpha1/generated.proto
it reminds me that:
pkg/apis/workflow/v1alpha1/generated.proto:6:11: Expected ";"
It's a compile error which means the package name should not contain -
.
Are there any methods to use -
in package name or any workaround?
Thanks!
Protobuf
It's not allowed, neither by proto2 specs (as in your example code) nor by proto3 specs.
As shown in the specs (either of above mentioned), a package
declaration follows the pattern:
package = "package" fullIdent ";"
i.e. the keyword package
followed by a fullIdent
followed by one ;
semicolon, where fullIdent
is defined as:
fullIdent = ident { "." ident }
i.e. at least one ident
followed by zero or more other ident
's preceded by .
, where ident
is defined as:
ident = letter { letter | decimalDigit | "_" }
i.e. at least one letter, followed by zero or more letters ([A-Z]
, [a-z]
), digits ([0-9]
), or the underscore _
character.
So in conclusion, you can't have a minus (dash) -
character in your protobuf package name.
Go
Additionally, as @colm.anseo pointed out, Go package names also don't allow dash -
characters either:
PackageName = identifier .
where identifier = letter { letter | unicode_digit } .