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