From 5d55d4983aeffc6df603af356d5762fe0adb89b6 Mon Sep 17 00:00:00 2001 From: Jrohy Date: Sun, 9 Apr 2023 21:50:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/root.go | 2 +- core/client.go | 4 ++-- core/mysql.go | 4 ++-- core/tools.go | 15 +++++++-------- trojan/trojan.go | 4 ++-- util/command.go | 4 ++-- util/linux.go | 6 +++--- web/controller/data.go | 4 ++-- web/web.go | 2 +- 9 files changed, 22 insertions(+), 23 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index bdfcb72a..a2f75e06 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -47,7 +47,7 @@ exit: menuList := []string{"trojan管理", "用户管理", "安装管理", "web管理", "查看配置", "生成json"} switch util.LoopInput("请选择: ", menuList, false) { case 1: - trojan.ControllMenu() + trojan.ControlMenu() case 2: trojan.UserMenu() case 3: diff --git a/core/client.go b/core/client.go index 1b6d33ea..2134e954 100644 --- a/core/client.go +++ b/core/client.go @@ -3,7 +3,7 @@ package core import ( "encoding/json" "fmt" - "io/ioutil" + "os" "trojan/asset" ) @@ -42,7 +42,7 @@ func WriteClient(port int, password, domain, writePath string) bool { fmt.Println(err) return false } - if err = ioutil.WriteFile(writePath, outData, 0644); err != nil { + if err = os.WriteFile(writePath, outData, 0644); err != nil { fmt.Println(err) return false } diff --git a/core/mysql.go b/core/mysql.go index 84212c9e..d3426d53 100644 --- a/core/mysql.go +++ b/core/mysql.go @@ -6,7 +6,7 @@ import ( "errors" "fmt" mysqlDriver "github.com/go-sql-driver/mysql" - "io/ioutil" + "io" "log" "time" @@ -70,7 +70,7 @@ CREATE TABLE IF NOT EXISTS users ( // GetDB 获取mysql数据库连接 func (mysql *Mysql) GetDB() *sql.DB { // 屏蔽mysql驱动包的日志输出 - mysqlDriver.SetLogger(log.New(ioutil.Discard, "", 0)) + mysqlDriver.SetLogger(log.New(io.Discard, "", 0)) conn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", mysql.Username, mysql.Password, mysql.ServerAddr, mysql.ServerPort, mysql.Database) db, err := sql.Open("mysql", conn) if err != nil { diff --git a/core/tools.go b/core/tools.go index b6883a5d..b738c190 100644 --- a/core/tools.go +++ b/core/tools.go @@ -6,7 +6,6 @@ import ( "encoding/base64" "errors" "fmt" - "io/ioutil" "os" "strings" "trojan/util" @@ -19,8 +18,8 @@ func (mysql *Mysql) UpgradeDB() error { return errors.New("can't connect mysql") } var field string - error := db.QueryRow("SHOW COLUMNS FROM users LIKE 'passwordShow';").Scan(&field) - if error == sql.ErrNoRows { + err := db.QueryRow("SHOW COLUMNS FROM users LIKE 'passwordShow';").Scan(&field) + if err == sql.ErrNoRows { fmt.Println(util.Yellow("正在进行数据库升级, 请稍等..")) if _, err := db.Exec("ALTER TABLE users ADD COLUMN passwordShow VARCHAR(255) NOT NULL AFTER password;"); err != nil { fmt.Println(err) @@ -43,8 +42,8 @@ func (mysql *Mysql) UpgradeDB() error { } } } - error = db.QueryRow("SHOW COLUMNS FROM users LIKE 'useDays';").Scan(&field) - if error == sql.ErrNoRows { + err = db.QueryRow("SHOW COLUMNS FROM users LIKE 'useDays';").Scan(&field) + if err == sql.ErrNoRows { fmt.Println(util.Yellow("正在进行数据库升级, 请稍等..")) if _, err := db.Exec(` ALTER TABLE users @@ -56,10 +55,10 @@ ADD COLUMN expiryDate char(10) DEFAULT ''; } } var tableName string - error = db.QueryRow(fmt.Sprintf( + err = db.QueryRow(fmt.Sprintf( "SELECT * FROM information_schema.TABLES WHERE TABLE_NAME = 'users' AND TABLE_SCHEMA = '%s' ", mysql.Database) + " AND TABLE_COLLATION LIKE 'utf8%';").Scan(&tableName) - if error == sql.ErrNoRows { + if err == sql.ErrNoRows { tempFile := "temp.sql" mysql.DumpSql(tempFile) mysql.ExecSql(tempFile) @@ -96,7 +95,7 @@ INSERT INTO users(username, password, passwordShow, quota, download, upload, use // ExecSql 执行sql func (mysql *Mysql) ExecSql(filePath string) error { db := mysql.GetDB() - fileByte, err := ioutil.ReadFile(filePath) + fileByte, err := os.ReadFile(filePath) if err != nil { return err } diff --git a/trojan/trojan.go b/trojan/trojan.go index 9467de4a..6da673c8 100644 --- a/trojan/trojan.go +++ b/trojan/trojan.go @@ -12,8 +12,8 @@ import ( "trojan/util" ) -// ControllMenu Trojan控制菜单 -func ControllMenu() { +// ControlMenu Trojan控制菜单 +func ControlMenu() { fmt.Println() tType := Type() if tType == "trojan" { diff --git a/util/command.go b/util/command.go index 212f43b7..9863050a 100644 --- a/util/command.go +++ b/util/command.go @@ -3,7 +3,7 @@ package util import ( "bufio" "fmt" - "io/ioutil" + "io" "net/http" "os/exec" "strings" @@ -92,7 +92,7 @@ func RunWebShell(webShellPath string) { fmt.Println(err.Error()) } defer resp.Body.Close() - installShell, err := ioutil.ReadAll(resp.Body) + installShell, err := io.ReadAll(resp.Body) if err != nil { fmt.Println(err.Error()) } diff --git a/util/linux.go b/util/linux.go index b530ac0f..0f2878f5 100644 --- a/util/linux.go +++ b/util/linux.go @@ -3,7 +3,7 @@ package util import ( "bufio" "fmt" - "io/ioutil" + "io" "math/rand" "net" "net/http" @@ -27,7 +27,7 @@ func PortIsUse(port int) bool { // RandomPort 获取没占用的随机端口 func RandomPort() int { for { - rand.Seed(time.Now().UnixNano()) + rand.New(rand.NewSource(time.Now().UnixNano())) newPort := rand.Intn(65536) if !PortIsUse(newPort) { return newPort @@ -54,7 +54,7 @@ func GetLocalIP() string { resp, _ = http.Get("http://icanhazip.com") } defer resp.Body.Close() - s, _ := ioutil.ReadAll(resp.Body) + s, _ := io.ReadAll(resp.Body) return string(s) } diff --git a/web/controller/data.go b/web/controller/data.go index 4875878d..a019f1e3 100644 --- a/web/controller/data.go +++ b/web/controller/data.go @@ -77,8 +77,8 @@ func UpdateResetDay(day uint) *ResponseBody { return &responseBody } -// SheduleTask 定时任务 -func SheduleTask() { +// ScheduleTask 定时任务 +func ScheduleTask() { loc, _ := time.LoadLocation("Asia/Shanghai") c = cron.New(cron.WithLocation(loc)) c.AddFunc("@daily", func() { diff --git a/web/web.go b/web/web.go index 9159ea2f..03f0de61 100644 --- a/web/web.go +++ b/web/web.go @@ -183,7 +183,7 @@ func Start(host string, port, timeout int, isSSL bool) { userRouter(router) dataRouter(router) commonRouter(router) - controller.SheduleTask() + controller.ScheduleTask() controller.CollectTask() util.OpenPort(port) if isSSL {