重构RPC逻辑

This commit is contained in:
marvzhang
2020-03-10 12:08:26 +08:00
parent ab33640a50
commit e5b4ac6310
13 changed files with 386 additions and 227 deletions

14
backend/utils/rpc.go Normal file
View File

@@ -0,0 +1,14 @@
package utils
import "encoding/json"
// Object 转化为 String
func ObjectToString(params interface{}) string {
bytes, _ := json.Marshal(params)
return BytesToString(bytes)
}
// 获取 RPC 参数
func GetRpcParam(key string, params map[string]string) string {
return params[key]
}

46
backend/utils/system.go Normal file
View File

@@ -0,0 +1,46 @@
package utils
import "crawlab/entity"
func GetLangList() []entity.Lang {
list := []entity.Lang{
{
Name: "Python",
ExecutableName: "python",
ExecutablePaths: []string{"/usr/bin/python", "/usr/local/bin/python"},
DepExecutablePath: "/usr/local/bin/pip",
LockPath: "/tmp/install-python.lock",
},
{
Name: "Node.js",
ExecutableName: "node",
ExecutablePaths: []string{"/usr/bin/node", "/usr/local/bin/node"},
DepExecutablePath: "/usr/local/bin/npm",
LockPath: "/tmp/install-nodejs.lock",
},
{
Name: "Java",
ExecutableName: "java",
ExecutablePaths: []string{"/usr/bin/java", "/usr/local/bin/java"},
LockPath: "/tmp/install-java.lock",
},
}
return list
}
// 获取语言列表
func GetLangListPlain() []entity.Lang {
list := GetLangList()
return list
}
// 根据语言名获取语言实例,不包含状态
func GetLangFromLangNamePlain(name string) entity.Lang {
langList := GetLangListPlain()
for _, lang := range langList {
if lang.ExecutableName == name {
return lang
}
}
return entity.Lang{}
}