protogen, cmd/protoc-gen-go: initial commit
Package protogen provides support for writing protoc plugins.
A "plugin" in this case is a program run by protoc to generate output.
The protoc-gen-go command is a protoc plugin to generate Go code.
cmd/protoc-gen-go/golden_test.go is mostly a straight copy from
the golden test in github.com/golang/protobuf.
Change-Id: I332d0df1e4b60bb8cd926320b8721e16b99a4b71
Reviewed-on: https://go-review.googlesource.com/130175
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/cmd/protoc-gen-go/main.go b/cmd/protoc-gen-go/main.go
new file mode 100644
index 0000000..9ea1420
--- /dev/null
+++ b/cmd/protoc-gen-go/main.go
@@ -0,0 +1,35 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// The protoc-gen-go binary is a protoc plugin to generate a Go protocol
+// buffer package.
+package main
+
+import (
+ "strings"
+
+ "google.golang.org/proto/protogen"
+)
+
+func main() {
+ protogen.Run(func(gen *protogen.Plugin) error {
+ for _, f := range gen.Files {
+ if !f.Generate {
+ continue
+ }
+ genFile(gen, f)
+ }
+ return nil
+ })
+}
+
+func genFile(gen *protogen.Plugin, f *protogen.File) {
+ g := gen.NewGeneratedFile(strings.TrimSuffix(f.Desc.GetName(), ".proto") + ".pb.go")
+ g.P("// Code generated by protoc-gen-go. DO NOT EDIT.")
+ g.P("// source: ", f.Desc.GetName())
+ g.P()
+ g.P("package TODO")
+
+ // TODO: Everything.
+}