1// 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 Go code for 6// both proto2 and proto3 versions of the protocol buffer language. 7// 8// For more information about the usage of this plugin, see: 9// https://protobuf.dev/reference/go/go-generated. 10package main 11 12import ( 13 "errors" 14 "flag" 15 "fmt" 16 "os" 17 "path/filepath" 18 19 gengo "google.golang.org/protobuf/cmd/protoc-gen-go/internal_gengo" 20 "google.golang.org/protobuf/compiler/protogen" 21 "google.golang.org/protobuf/internal/version" 22) 23 24const genGoDocURL = "https://protobuf.dev/reference/go/go-generated" 25const grpcDocURL = "https://grpc.io/docs/languages/go/quickstart/#regenerate-grpc-code" 26 27func main() { 28 if len(os.Args) == 2 && os.Args[1] == "--version" { 29 fmt.Fprintf(os.Stdout, "%v %v\n", filepath.Base(os.Args[0]), version.String()) 30 os.Exit(0) 31 } 32 if len(os.Args) == 2 && os.Args[1] == "--help" { 33 fmt.Fprintf(os.Stdout, "See "+genGoDocURL+" for usage information.\n") 34 os.Exit(0) 35 } 36 37 var ( 38 flags flag.FlagSet 39 plugins = flags.String("plugins", "", "deprecated option") 40 ) 41 protogen.Options{ 42 ParamFunc: flags.Set, 43 }.Run(func(gen *protogen.Plugin) error { 44 if *plugins != "" { 45 return errors.New("protoc-gen-go: plugins are not supported; use 'protoc --go-grpc_out=...' to generate gRPC\n\n" + 46 "See " + grpcDocURL + " for more information.") 47 } 48 for _, f := range gen.Files { 49 if f.Generate { 50 gengo.GenerateFile(gen, f) 51 } 52 } 53 gen.SupportedFeatures = gengo.SupportedFeatures 54 return nil 55 }) 56} 57