diff --git a/asset/asset.go b/asset/asset.go index 6dfe0616..0c810052 100644 --- a/asset/asset.go +++ b/asset/asset.go @@ -1,19 +1,12 @@ package asset -import _ "embed" +import "embed" -//go:embed trojan-install.sh -var installF string +//go:embed trojan-install.sh client.json +var f embed.FS -//go:embed client.json -var clientF string - -// GetAssetStr 获取资源字符串 -func GetAssetStr(ftype int) string { - if ftype == 0 { - return installF - } else if ftype == 1 { - return clientF - } - return "" +// GetAsset 获取资源字符串 +func GetAsset(name string) []byte { + data, _ := f.ReadFile(name) + return data } diff --git a/core/client.go b/core/client.go index c079d17d..1b6d33ea 100644 --- a/core/client.go +++ b/core/client.go @@ -28,9 +28,9 @@ type ClientTCP struct { // WriteClient 生成客户端json func WriteClient(port int, password, domain, writePath string) bool { - data := asset.GetAssetStr(1) + data := asset.GetAsset("client.json") config := ClientConfig{} - if err := json.Unmarshal([]byte(data), &config); err != nil { + if err := json.Unmarshal(data, &config); err != nil { fmt.Println(err) return false } diff --git a/trojan/install.go b/trojan/install.go index ea5812a9..3d3f0342 100644 --- a/trojan/install.go +++ b/trojan/install.go @@ -50,7 +50,7 @@ func InstallDocker() { // InstallTrojan 安装trojan func InstallTrojan() { fmt.Println() - data := asset.GetAssetStr(0) + data := string(asset.GetAsset("trojan-install.sh")) if util.ExecCommandWithResult("systemctl list-unit-files|grep trojan.service") != "" && Type() == "trojan-go" { data = strings.ReplaceAll(data, "TYPE=0", "TYPE=1") }