优化代码

This commit is contained in:
刘祥超
2022-08-04 11:51:34 +08:00
parent 529b7041e7
commit dad8802fb0
15 changed files with 52 additions and 58 deletions

View File

@@ -7,7 +7,7 @@ import (
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/maps"
"gopkg.in/yaml.v3"
"io/ioutil"
"os"
"strings"
)
@@ -23,7 +23,7 @@ func (this *IndexAction) RunGet(params struct{}) {
this.Data["error"] = ""
configFile := Tea.ConfigFile("api_db.yaml")
data, err := ioutil.ReadFile(configFile)
data, err := os.ReadFile(configFile)
if err != nil {
this.Data["error"] = "read config file failed: api_db.yaml: " + err.Error()
this.Show()

View File

@@ -10,8 +10,8 @@ import (
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/maps"
"gopkg.in/yaml.v3"
"io/ioutil"
"net"
"os"
"regexp"
"strings"
)
@@ -34,7 +34,7 @@ func (this *UpdateAction) RunGet(params struct{}) {
}
configFile := Tea.ConfigFile("api_db.yaml")
data, err := ioutil.ReadFile(configFile)
data, err := os.ReadFile(configFile)
if err != nil {
return
}
@@ -144,7 +144,7 @@ dbs:
models:
package: internal/web/models
`
err := ioutil.WriteFile(configFile, []byte(template), 0666)
err := os.WriteFile(configFile, []byte(template), 0666)
if err != nil {
this.Fail("保存配置失败:" + err.Error())
}

View File

@@ -8,8 +8,8 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/actions"
"io/ioutil"
"net"
"os"
)
type UpdateHTTPSPopupAction struct {
@@ -31,12 +31,12 @@ func (this *UpdateHTTPSPopupAction) RunGet(params struct{}) {
// 证书
certConfigs := []*sslconfigs.SSLCertConfig{}
if len(serverConfig.Https.Cert) > 0 && len(serverConfig.Https.Key) > 0 {
certData, err := ioutil.ReadFile(Tea.Root + "/" + serverConfig.Https.Cert)
certData, err := os.ReadFile(Tea.Root + "/" + serverConfig.Https.Cert)
if err != nil {
this.ErrorPage(err)
return
}
keyData, err := ioutil.ReadFile(Tea.Root + "/" + serverConfig.Https.Key)
keyData, err := os.ReadFile(Tea.Root + "/" + serverConfig.Https.Key)
if err != nil {
this.ErrorPage(err)
return
@@ -120,11 +120,11 @@ func (this *UpdateHTTPSPopupAction) RunPost(params struct {
this.ErrorPage(err)
return
}
err = ioutil.WriteFile(Tea.ConfigFile("https.key.pem"), certConfig.KeyData, 0666)
err = os.WriteFile(Tea.ConfigFile("https.key.pem"), certConfig.KeyData, 0666)
if err != nil {
this.Fail("保存密钥失败:" + err.Error())
}
err = ioutil.WriteFile(Tea.ConfigFile("https.cert.pem"), certConfig.CertData, 0666)
err = os.WriteFile(Tea.ConfigFile("https.cert.pem"), certConfig.CertData, 0666)
if err != nil {
this.Fail("保存证书失败:" + err.Error())
}

View File

@@ -4,7 +4,7 @@ import (
"github.com/iwind/TeaGo"
"github.com/iwind/TeaGo/Tea"
"gopkg.in/yaml.v3"
"io/ioutil"
"os"
)
var serverConfigIsChanged = false
@@ -12,7 +12,7 @@ var serverConfigIsChanged = false
// 读取当前服务配置
func loadServerConfig() (*TeaGo.ServerConfig, error) {
configFile := Tea.ConfigFile("server.yaml")
data, err := ioutil.ReadFile(configFile)
data, err := os.ReadFile(configFile)
if err != nil {
return nil, err
}
@@ -30,7 +30,7 @@ func writeServerConfig(serverConfig *TeaGo.ServerConfig) error {
if err != nil {
return err
}
err = ioutil.WriteFile(Tea.ConfigFile("server.yaml"), data, 0666)
err = os.WriteFile(Tea.ConfigFile("server.yaml"), data, 0666)
if err != nil {
return err
}

View File

@@ -11,7 +11,7 @@ import (
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
stringutil "github.com/iwind/TeaGo/utils/string"
"io/ioutil"
"io"
"net/http"
"runtime"
"strings"
@@ -70,7 +70,7 @@ func (this *IndexAction) RunPost(params struct {
defer func() {
_ = resp.Body.Close()
}()
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
this.Data["result"] = maps.Map{
"isOk": false,