blob: 5792ebeed1b82d58e7c24bb4afc00b22a1be5a6a [file] [log] [blame]
Damien Neil220c2022018-08-15 11:24:18 -07001// Copyright 2018 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// The protoc-gen-go binary is a protoc plugin to generate a Go protocol
6// buffer package.
7package main
8
9import (
Damien Neil220c2022018-08-15 11:24:18 -070010 "google.golang.org/proto/protogen"
11)
12
13func main() {
14 protogen.Run(func(gen *protogen.Plugin) error {
15 for _, f := range gen.Files {
16 if !f.Generate {
17 continue
18 }
19 genFile(gen, f)
20 }
21 return nil
22 })
23}
24
25func genFile(gen *protogen.Plugin, f *protogen.File) {
Damien Neil082ce922018-09-06 10:23:53 -070026 g := gen.NewGeneratedFile(f.GeneratedFilenamePrefix+".pb.go", f.GoImportPath)
Damien Neil220c2022018-08-15 11:24:18 -070027 g.P("// Code generated by protoc-gen-go. DO NOT EDIT.")
Damien Neilabc6fc12018-08-23 14:39:30 -070028 g.P("// source: ", f.Desc.Path())
Damien Neil220c2022018-08-15 11:24:18 -070029 g.P()
Damien Neil082ce922018-09-06 10:23:53 -070030 g.P("package ", f.GoPackageName)
Damien Neilc7d07d92018-08-22 13:46:02 -070031 g.P()
32
33 for _, m := range f.Messages {
34 genMessage(gen, g, m)
35 }
Damien Neil220c2022018-08-15 11:24:18 -070036
37 // TODO: Everything.
38}
Damien Neilc7d07d92018-08-22 13:46:02 -070039
40func genMessage(gen *protogen.Plugin, g *protogen.GeneratedFile, m *protogen.Message) {
41 g.P("type ", m.GoIdent, " struct {")
42 g.P("}")
43 g.P()
44
45 for _, nested := range m.Messages {
46 genMessage(gen, g, nested)
47 }
48}