增加protobuf文件编译工具
This commit is contained in:
parent
6552fd47cd
commit
51c9eae500
1194
protobuf/device_state.pb.go
Normal file
1194
protobuf/device_state.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,5 +0,0 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
53
protobuf/main/main.go
Normal file
53
protobuf/main/main.go
Normal file
@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var (
|
||||
basePath, _ = os.Getwd()
|
||||
protoFolder = filepath.Join(basePath, "bj-rtss-message", "protos")
|
||||
protocPath = filepath.Join(basePath, "bj-rtss-message", "protoc-23.1", "bin", "win64", "protoc")
|
||||
)
|
||||
|
||||
func main() {
|
||||
//先安装以下插件
|
||||
//go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
||||
|
||||
protoFiles := getProtoFiles()
|
||||
// 编译proto文件为Go文件
|
||||
if err := compileProto(protoFiles); err != nil {
|
||||
log.Fatalf("编译proto文件失败:%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// 获取指定文件夹下的所有proto文件的绝对路径列表
|
||||
func getProtoFiles() []string {
|
||||
var protoFiles []string
|
||||
files, err := os.ReadDir(protoFolder)
|
||||
if err != nil {
|
||||
log.Fatal("获取proto文件列表失败")
|
||||
}
|
||||
for _, file := range files {
|
||||
protoFiles = append(protoFiles, file.Name())
|
||||
}
|
||||
return protoFiles
|
||||
}
|
||||
|
||||
// 编译proto文件为Go文件
|
||||
func compileProto(protoFiles []string) error {
|
||||
for _, protoFile := range protoFiles {
|
||||
cmd := exec.Command(protocPath, "--proto_path="+protoFolder, "--go_out=./", protoFile)
|
||||
fmt.Println(cmd.String())
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
3187
protobuf/stationLayoutGraphics.pb.go
Normal file
3187
protobuf/stationLayoutGraphics.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user