Skip to content

Commit

Permalink
优化静态资源获取
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrohy committed Apr 2, 2021
1 parent 7533576 commit 199a1e6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
21 changes: 7 additions & 14 deletions asset/asset.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion trojan/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 199a1e6

Please sign in to comment.