@@ -38,48 +38,60 @@ func main() {
38
38
39
39
// Set of generated proto packages to forward to v2.
40
40
files := []struct {
41
- goPkg string
42
- pbDesc protoreflect.FileDescriptor
41
+ oldGoPkg string
42
+ newGoPkg string
43
+ pbDesc protoreflect.FileDescriptor
43
44
}{{
44
- goPkg : "github.com/golang/protobuf/protoc-gen-go/descriptor;descriptor" ,
45
- pbDesc : descriptorpb .File_google_protobuf_descriptor_proto ,
45
+ oldGoPkg : "github.com/golang/protobuf/protoc-gen-go/descriptor;descriptor" ,
46
+ newGoPkg : "google.golang.org/protobuf/types/descriptorpb" ,
47
+ pbDesc : descriptorpb .File_google_protobuf_descriptor_proto ,
46
48
}, {
47
- goPkg : "github.com/golang/protobuf/protoc-gen-go/plugin;plugin_go" ,
48
- pbDesc : pluginpb .File_google_protobuf_compiler_plugin_proto ,
49
+ oldGoPkg : "github.com/golang/protobuf/protoc-gen-go/plugin;plugin_go" ,
50
+ newGoPkg : "google.golang.org/protobuf/types/pluginpb" ,
51
+ pbDesc : pluginpb .File_google_protobuf_compiler_plugin_proto ,
49
52
}, {
50
- goPkg : "github.com/golang/protobuf/ptypes/any;any" ,
51
- pbDesc : anypb .File_google_protobuf_any_proto ,
53
+ oldGoPkg : "github.com/golang/protobuf/ptypes/any;any" ,
54
+ newGoPkg : "google.golang.org/protobuf/types/known/anypb" ,
55
+ pbDesc : anypb .File_google_protobuf_any_proto ,
52
56
}, {
53
- goPkg : "github.com/golang/protobuf/ptypes/duration;duration" ,
54
- pbDesc : durationpb .File_google_protobuf_duration_proto ,
57
+ oldGoPkg : "github.com/golang/protobuf/ptypes/duration;duration" ,
58
+ newGoPkg : "google.golang.org/protobuf/types/known/durationpb" ,
59
+ pbDesc : durationpb .File_google_protobuf_duration_proto ,
55
60
}, {
56
- goPkg : "github.com/golang/protobuf/ptypes/timestamp;timestamp" ,
57
- pbDesc : timestamppb .File_google_protobuf_timestamp_proto ,
61
+ oldGoPkg : "github.com/golang/protobuf/ptypes/timestamp;timestamp" ,
62
+ newGoPkg : "google.golang.org/protobuf/types/known/timestamppb" ,
63
+ pbDesc : timestamppb .File_google_protobuf_timestamp_proto ,
58
64
}, {
59
- goPkg : "github.com/golang/protobuf/ptypes/wrappers;wrappers" ,
60
- pbDesc : wrapperspb .File_google_protobuf_wrappers_proto ,
65
+ oldGoPkg : "github.com/golang/protobuf/ptypes/wrappers;wrappers" ,
66
+ newGoPkg : "google.golang.org/protobuf/types/known/wrapperspb" ,
67
+ pbDesc : wrapperspb .File_google_protobuf_wrappers_proto ,
61
68
}, {
62
- goPkg : "github.com/golang/protobuf/ptypes/struct;structpb" ,
63
- pbDesc : structpb .File_google_protobuf_struct_proto ,
69
+ oldGoPkg : "github.com/golang/protobuf/ptypes/struct;structpb" ,
70
+ newGoPkg : "google.golang.org/protobuf/types/known/structpb" ,
71
+ pbDesc : structpb .File_google_protobuf_struct_proto ,
64
72
}, {
65
- goPkg : "github.com/golang/protobuf/ptypes/empty;empty" ,
66
- pbDesc : emptypb .File_google_protobuf_empty_proto ,
73
+ oldGoPkg : "github.com/golang/protobuf/ptypes/empty;empty" ,
74
+ newGoPkg : "google.golang.org/protobuf/types/known/emptypb" ,
75
+ pbDesc : emptypb .File_google_protobuf_empty_proto ,
67
76
}}
68
77
69
78
// For each package, construct a proto file that public imports the package.
70
79
var req pluginpb.CodeGeneratorRequest
80
+ var flags []string
71
81
for _ , file := range files {
72
- pkgPath := file .goPkg [:strings .IndexByte (file .goPkg , ';' )]
82
+ pkgPath := file .oldGoPkg [:strings .IndexByte (file .oldGoPkg , ';' )]
73
83
fd := & descriptorpb.FileDescriptorProto {
74
84
Name : proto .String (pkgPath + "/" + path .Base (pkgPath ) + ".proto" ),
75
85
Syntax : proto .String (file .pbDesc .Syntax ().String ()),
76
86
Dependency : []string {file .pbDesc .Path ()},
77
87
PublicDependency : []int32 {0 },
78
- Options : & descriptorpb.FileOptions {GoPackage : proto .String (file .goPkg )},
88
+ Options : & descriptorpb.FileOptions {GoPackage : proto .String (file .oldGoPkg )},
79
89
}
80
90
req .ProtoFile = append (req .ProtoFile , protodesc .ToFileDescriptorProto (file .pbDesc ), fd )
81
91
req .FileToGenerate = append (req .FileToGenerate , fd .GetName ())
92
+ flags = append (flags , "M" + file .pbDesc .Path ()+ "=" + file .newGoPkg )
82
93
}
94
+ req .Parameter = proto .String (strings .Join (flags , "," ))
83
95
84
96
// Use the internal logic of protoc-gen-go to generate the files.
85
97
gen , err := protogen.Options {}.New (& req )
0 commit comments