1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-01-04 08:15:21 -05:00

Adjust Protocol Buffers (#109)

* Update protoc binary executable files to v3.13.0

* Write proto files in more standard way

* Make go generate & vprotogen compatible with protoc-gen-gofast

* Regenerate pb.go files according to new proto files

* Clean go.sum by running go mod tidy

* Implement mustEmbedUnimplementedServiceServer for gPRC services
This commit is contained in:
Loyalsoldier
2020-08-24 20:10:26 +08:00
committed by GitHub
parent 969f68ba24
commit ef460f68f8
120 changed files with 4693 additions and 4437 deletions

View File

@@ -1,17 +1,13 @@
package main
import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"v2ray.com/core/common"
)
var protocMap = map[string]string{
@@ -51,45 +47,27 @@ func main() {
return nil
})
var protoFilesUsingProtocGenGoFast = map[string]bool{"proxy/vless/encoding/addons.proto": true}
for _, files := range protofiles {
args := []string{"--proto_path", gosrc, "--go_out", "plugins=grpc:" + gosrc}
args = append(args, files...)
cmd := exec.Command(protoc, args...)
cmd.Env = append(cmd.Env, os.Environ()...)
output, err := cmd.CombinedOutput()
if len(output) > 0 {
fmt.Println(string(output))
}
if err != nil {
fmt.Println(err)
for _, absPath := range files {
relPath, _ := filepath.Rel(reporoot, absPath)
args := make([]string, 0)
if protoFilesUsingProtocGenGoFast[relPath] {
args = []string{"--proto_path", reporoot, "--gofast_out", gosrc}
} else {
args = []string{"--proto_path", reporoot, "--go_out", gosrc, "--go-grpc_out", gosrc}
}
args = append(args, absPath)
cmd := exec.Command(protoc, args...)
cmd.Env = append(cmd.Env, os.Environ()...)
output, err := cmd.CombinedOutput()
if len(output) > 0 {
fmt.Println(string(output))
}
if err != nil {
fmt.Println(err)
}
}
}
common.Must(filepath.Walk(reporoot, func(path string, info os.FileInfo, err error) error {
if err != nil {
fmt.Println(err)
return err
}
if info.IsDir() {
return nil
}
if !strings.HasSuffix(info.Name(), ".pb.go") {
return nil
}
content, err := ioutil.ReadFile(path)
if err != nil {
return err
}
content = bytes.Replace(content, []byte("\"golang.org/x/net/context\""), []byte("\"context\""), 1)
pos := bytes.Index(content, []byte("\npackage"))
if pos > 0 {
content = content[pos+1:]
}
return ioutil.WriteFile(path, content, info.Mode())
}))
}