|
@@ -1,10 +1,10 @@
|
|
package h_compile_plugin
|
|
package h_compile_plugin
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "cicv-data-closedloop/aarch64/plugin-compile/package/config/c_oss"
|
|
|
|
+ util2 "cicv-data-closedloop/aarch64/plugin-compile/package/util"
|
|
"cicv-data-closedloop/common/config/c_log"
|
|
"cicv-data-closedloop/common/config/c_log"
|
|
"cicv-data-closedloop/common/entity"
|
|
"cicv-data-closedloop/common/entity"
|
|
- "cicv-data-closedloop/plugin-compile/package/config/c_oss"
|
|
|
|
- "cicv-data-closedloop/plugin-compile/package/util"
|
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
"github.com/google/uuid"
|
|
"github.com/google/uuid"
|
|
@@ -61,7 +61,7 @@ func (h *CompileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
tempMiddlePath := uuid.New().String()[:8]
|
|
tempMiddlePath := uuid.New().String()[:8]
|
|
goLocalPath := codeDir + tempMiddlePath + "/main/" + tempMiddlePath + ".go"
|
|
goLocalPath := codeDir + tempMiddlePath + "/main/" + tempMiddlePath + ".go"
|
|
c_log.GlobalLogger.Infof("下载源代码 %v --> %v", goObjectKey, goLocalPath)
|
|
c_log.GlobalLogger.Infof("下载源代码 %v --> %v", goObjectKey, goLocalPath)
|
|
- if err := util.LimitDownload(c_oss.OssBucket, 41943040, goObjectKey, goLocalPath); err != nil {
|
|
|
|
|
|
+ if err := util2.LimitDownload(c_oss.OssBucket, 41943040, goObjectKey, goLocalPath); err != nil {
|
|
c_log.GlobalLogger.Error("下载源代码 ", goObjectKey, " 出错:", err)
|
|
c_log.GlobalLogger.Error("下载源代码 ", goObjectKey, " 出错:", err)
|
|
result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1004", Message: "下载源代码 " + goObjectKey + " 出错。"})
|
|
result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1004", Message: "下载源代码 " + goObjectKey + " 出错。"})
|
|
_, _ = fmt.Fprintf(w, string(result))
|
|
_, _ = fmt.Fprintf(w, string(result))
|
|
@@ -80,7 +80,7 @@ func (h *CompileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
copiedCompileCmdArgs := make([]string, len(compileCmdArgs))
|
|
copiedCompileCmdArgs := make([]string, len(compileCmdArgs))
|
|
copy(copiedCompileCmdArgs, compileCmdArgs)
|
|
copy(copiedCompileCmdArgs, compileCmdArgs)
|
|
copiedCompileCmdArgs = append(copiedCompileCmdArgs, "-o", soLocalPath, goLocalPath)
|
|
copiedCompileCmdArgs = append(copiedCompileCmdArgs, "-o", soLocalPath, goLocalPath)
|
|
- if _, output, err := util.ExecuteWithEnvAndDir(os.Environ(), codeDir, compileCmd, copiedCompileCmdArgs...); err != nil {
|
|
|
|
|
|
+ if _, output, err := util2.ExecuteWithEnvAndDir(os.Environ(), codeDir, compileCmd, copiedCompileCmdArgs...); err != nil {
|
|
c_log.GlobalLogger.Error("编译插件 ", goLocalPath, " 出错:【命令】=", compileCmd, " ", copiedCompileCmdArgs, "【output】=", output, ",【err】=", err)
|
|
c_log.GlobalLogger.Error("编译插件 ", goLocalPath, " 出错:【命令】=", compileCmd, " ", copiedCompileCmdArgs, "【output】=", output, ",【err】=", err)
|
|
result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1006", Message: "编译插件 " + goObjectKey + " 出错。"})
|
|
result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1006", Message: "编译插件 " + goObjectKey + " 出错。"})
|
|
_, _ = fmt.Fprintf(w, string(result))
|
|
_, _ = fmt.Fprintf(w, string(result))
|
|
@@ -88,7 +88,7 @@ func (h *CompileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
|
|
|
|
// 4 校验插件是否能用
|
|
// 4 校验插件是否能用
|
|
- if _, output, err := util.Execute(vaildateCmd, soLocalPath); err != nil || output != "0" {
|
|
|
|
|
|
+ if _, output, err := util2.Execute(vaildateCmd, soLocalPath); err != nil || output != "0" {
|
|
c_log.GlobalLogger.Error("插件 ", goLocalPath, " 校验失败:【命令】=", vaildateCmd, " ", soLocalPath, "【output】=", output)
|
|
c_log.GlobalLogger.Error("插件 ", goLocalPath, " 校验失败:【命令】=", vaildateCmd, " ", soLocalPath, "【output】=", output)
|
|
result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1007", Message: "插件 " + soObjectKey + " 校验失败。"})
|
|
result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1007", Message: "插件 " + soObjectKey + " 校验失败。"})
|
|
_, _ = fmt.Fprintf(w, string(result))
|
|
_, _ = fmt.Fprintf(w, string(result))
|
|
@@ -96,14 +96,14 @@ func (h *CompileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
c_log.GlobalLogger.Error("插件 ", soLocalPath, " 校验成功。")
|
|
c_log.GlobalLogger.Error("插件 ", soLocalPath, " 校验成功。")
|
|
// 5 如果插件能用,将插件上传到 oss
|
|
// 5 如果插件能用,将插件上传到 oss
|
|
- if err := util.LimitUpload(c_oss.OssBucket, 41943040, soObjectKey, soLocalPath); err != nil {
|
|
|
|
|
|
+ if err := util2.LimitUpload(c_oss.OssBucket, 41943040, soObjectKey, soLocalPath); err != nil {
|
|
c_log.GlobalLogger.Error("上传插件 ", soObjectKey, " 出错:", err)
|
|
c_log.GlobalLogger.Error("上传插件 ", soObjectKey, " 出错:", err)
|
|
result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1008", Message: "上传插件 " + soObjectKey + " 出错。"})
|
|
result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1008", Message: "上传插件 " + soObjectKey + " 出错。"})
|
|
_, _ = fmt.Fprintf(w, string(result))
|
|
_, _ = fmt.Fprintf(w, string(result))
|
|
return
|
|
return
|
|
}
|
|
}
|
|
// 6 删除本地缓存的源代码和插件
|
|
// 6 删除本地缓存的源代码和插件
|
|
- if err := util.RemoveDir(codeDir + tempMiddlePath + "/"); err != nil {
|
|
|
|
|
|
+ if err := util2.RemoveDir(codeDir + tempMiddlePath + "/"); err != nil {
|
|
c_log.GlobalLogger.Error("删除本地缓存目录 ", codeDir+tempMiddlePath+"/", " 出错:", err)
|
|
c_log.GlobalLogger.Error("删除本地缓存目录 ", codeDir+tempMiddlePath+"/", " 出错:", err)
|
|
result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1009", Message: "删除本地缓存出错。"})
|
|
result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1009", Message: "删除本地缓存出错。"})
|
|
_, _ = fmt.Fprintf(w, string(result))
|
|
_, _ = fmt.Fprintf(w, string(result))
|