mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-06 23:00:25 +08:00
优化代码
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
@@ -34,7 +33,7 @@ func LoadAPIConfig() (*APIConfig, error) {
|
|||||||
var data []byte
|
var data []byte
|
||||||
var err error
|
var err error
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
data, err = ioutil.ReadFile(path)
|
data, err = os.ReadFile(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if path == localFile {
|
if path == localFile {
|
||||||
isFromLocal = true
|
isFromLocal = true
|
||||||
@@ -54,7 +53,7 @@ func LoadAPIConfig() (*APIConfig, error) {
|
|||||||
|
|
||||||
if !isFromLocal {
|
if !isFromLocal {
|
||||||
// 恢复文件
|
// 恢复文件
|
||||||
_ = ioutil.WriteFile(localFile, data, 0666)
|
_ = os.WriteFile(localFile, data, 0666)
|
||||||
}
|
}
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
@@ -118,11 +117,11 @@ func (this *APIConfig) WriteFile(path string) error {
|
|||||||
dir := homeDir + "/." + teaconst.ProcessName
|
dir := homeDir + "/." + teaconst.ProcessName
|
||||||
stat, err := os.Stat(dir)
|
stat, err := os.Stat(dir)
|
||||||
if err == nil && stat.IsDir() {
|
if err == nil && stat.IsDir() {
|
||||||
_ = ioutil.WriteFile(dir+"/"+filename, data, 0666)
|
_ = os.WriteFile(dir+"/"+filename, data, 0666)
|
||||||
} else if err != nil && os.IsNotExist(err) {
|
} else if err != nil && os.IsNotExist(err) {
|
||||||
err = os.Mkdir(dir, 0777)
|
err = os.Mkdir(dir, 0777)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
_ = ioutil.WriteFile(dir+"/"+filename, data, 0666)
|
_ = os.WriteFile(dir+"/"+filename, data, 0666)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,16 +131,16 @@ func (this *APIConfig) WriteFile(path string) error {
|
|||||||
dir := "/etc/" + teaconst.ProcessName
|
dir := "/etc/" + teaconst.ProcessName
|
||||||
stat, err := os.Stat(dir)
|
stat, err := os.Stat(dir)
|
||||||
if err == nil && stat.IsDir() {
|
if err == nil && stat.IsDir() {
|
||||||
_ = ioutil.WriteFile(dir+"/"+filename, data, 0666)
|
_ = os.WriteFile(dir+"/"+filename, data, 0666)
|
||||||
} else if err != nil && os.IsNotExist(err) {
|
} else if err != nil && os.IsNotExist(err) {
|
||||||
err = os.Mkdir(dir, 0777)
|
err = os.Mkdir(dir, 0777)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
_ = ioutil.WriteFile(dir+"/"+filename, data, 0666)
|
_ = os.WriteFile(dir+"/"+filename, data, 0666)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ioutil.WriteFile(path, data, 0666)
|
err = os.WriteFile(path, data, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ package configs
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"io/ioutil"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
var plusConfigFile = "plus.cache.json"
|
var plusConfigFile = "plus.cache.json"
|
||||||
@@ -17,7 +17,7 @@ type PlusConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ReadPlusConfig() *PlusConfig {
|
func ReadPlusConfig() *PlusConfig {
|
||||||
data, err := ioutil.ReadFile(Tea.ConfigFile(plusConfigFile))
|
data, err := os.ReadFile(Tea.ConfigFile(plusConfigFile))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &PlusConfig{IsPlus: false}
|
return &PlusConfig{IsPlus: false}
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ func WritePlusConfig(config *PlusConfig) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(Tea.ConfigFile(plusConfigFile), configJSON, 0777)
|
err = os.WriteFile(Tea.ConfigFile(plusConfigFile), configJSON, 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"github.com/iwind/gosock/pkg/gosock"
|
"github.com/iwind/gosock/pkg/gosock"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
@@ -173,9 +172,9 @@ func (this *AdminNode) checkServer() error {
|
|||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
// 创建文件
|
// 创建文件
|
||||||
templateFile := Tea.ConfigFile("server.template.yaml")
|
templateFile := Tea.ConfigFile("server.template.yaml")
|
||||||
data, err := ioutil.ReadFile(templateFile)
|
data, err := os.ReadFile(templateFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = ioutil.WriteFile(configFile, data, 0666)
|
err = os.WriteFile(configFile, data, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("create config file failed: " + err.Error())
|
return errors.New("create config file failed: " + err.Error())
|
||||||
}
|
}
|
||||||
@@ -195,7 +194,7 @@ https:
|
|||||||
cert: ""
|
cert: ""
|
||||||
key: ""
|
key: ""
|
||||||
`
|
`
|
||||||
err = ioutil.WriteFile(configFile, []byte(templateYAML), 0666)
|
err = os.WriteFile(configFile, []byte(templateYAML), 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("create config file failed: " + err.Error())
|
return errors.New("create config file failed: " + err.Error())
|
||||||
}
|
}
|
||||||
@@ -210,7 +209,7 @@ https:
|
|||||||
// 添加端口到防火墙
|
// 添加端口到防火墙
|
||||||
func (this *AdminNode) addPortsToFirewall() {
|
func (this *AdminNode) addPortsToFirewall() {
|
||||||
var configFile = Tea.ConfigFile("server.yaml")
|
var configFile = Tea.ConfigFile("server.yaml")
|
||||||
data, err := ioutil.ReadFile(configFile)
|
data, err := os.ReadFile(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -263,9 +262,9 @@ func (this *AdminNode) startAPINode() {
|
|||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
_, err = os.Stat(path)
|
_, err = os.Stat(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = ioutil.WriteFile(configPath, data, 0666)
|
err = os.WriteFile(configPath, data, 0666)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
logs.Println("[NODE]recover 'edge-api/configs/api.yaml' from '" + path + "'")
|
logs.Println("[NODE]recover 'edge-api/configs/api.yaml' from '" + path + "'")
|
||||||
canStart = true
|
canStart = true
|
||||||
@@ -289,9 +288,9 @@ func (this *AdminNode) startAPINode() {
|
|||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
_, err = os.Stat(path)
|
_, err = os.Stat(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = ioutil.WriteFile(dbPath, data, 0666)
|
err = os.WriteFile(dbPath, data, 0666)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
logs.Println("[NODE]recover 'edge-api/configs/db.yaml' from '" + path + "'")
|
logs.Println("[NODE]recover 'edge-api/configs/db.yaml' from '" + path + "'")
|
||||||
break
|
break
|
||||||
@@ -316,12 +315,12 @@ func (this *AdminNode) startAPINode() {
|
|||||||
// 生成Secret
|
// 生成Secret
|
||||||
func (this *AdminNode) genSecret() string {
|
func (this *AdminNode) genSecret() string {
|
||||||
tmpFile := os.TempDir() + "/edge-admin-secret.tmp"
|
tmpFile := os.TempDir() + "/edge-admin-secret.tmp"
|
||||||
data, err := ioutil.ReadFile(tmpFile)
|
data, err := os.ReadFile(tmpFile)
|
||||||
if err == nil && len(data) == 32 {
|
if err == nil && len(data) == 32 {
|
||||||
return string(data)
|
return string(data)
|
||||||
}
|
}
|
||||||
secret := rands.String(32)
|
secret := rands.String(32)
|
||||||
_ = ioutil.WriteFile(tmpFile, []byte(secret), 0666)
|
_ = os.WriteFile(tmpFile, []byte(secret), 0666)
|
||||||
return secret
|
return secret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
stringutil "github.com/iwind/TeaGo/utils/string"
|
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -95,7 +95,7 @@ func (this *CheckUpdatesTask) Loop() error {
|
|||||||
defer func() {
|
defer func() {
|
||||||
_ = resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
}()
|
}()
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("read api failed: " + err.Error())
|
return errors.New("read api failed: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/files"
|
"github.com/iwind/TeaGo/files"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -83,13 +82,13 @@ func (this *ServiceManager) installInitService(exePath string, args []string) er
|
|||||||
return errors.New("'scripts/" + shortName + "' file not exists")
|
return errors.New("'scripts/" + shortName + "' file not exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(scriptFile)
|
data, err := os.ReadFile(scriptFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
data = regexp.MustCompile("INSTALL_DIR=.+").ReplaceAll(data, []byte("INSTALL_DIR="+Tea.Root))
|
data = regexp.MustCompile("INSTALL_DIR=.+").ReplaceAll(data, []byte("INSTALL_DIR="+Tea.Root))
|
||||||
err = ioutil.WriteFile(initServiceFile, data, 0777)
|
err = os.WriteFile(initServiceFile, data, 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -137,7 +136,7 @@ ExecReload=` + exePath + ` reload
|
|||||||
WantedBy=multi-user.target`
|
WantedBy=multi-user.target`
|
||||||
|
|
||||||
// write file
|
// write file
|
||||||
err := ioutil.WriteFile(systemdServiceFile, []byte(desc), 0777)
|
err := os.WriteFile(systemdServiceFile, []byte(desc), 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -68,7 +67,7 @@ func FailPage(action actions.ActionWrapper, err error) {
|
|||||||
var issuesHTML = ""
|
var issuesHTML = ""
|
||||||
if isLocalAPI {
|
if isLocalAPI {
|
||||||
// 读取本地API节点的issues
|
// 读取本地API节点的issues
|
||||||
issuesData, issuesErr := ioutil.ReadFile(Tea.Root + "/edge-api/logs/issues.log")
|
issuesData, issuesErr := os.ReadFile(Tea.Root + "/edge-api/logs/issues.log")
|
||||||
if issuesErr == nil {
|
if issuesErr == nil {
|
||||||
var issueMaps = []maps.Map{}
|
var issueMaps = []maps.Map{}
|
||||||
issuesErr = json.Unmarshal(issuesData, &issueMaps)
|
issuesErr = json.Unmarshal(issuesData, &issueMaps)
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -46,7 +45,7 @@ func (this *InstallAction) RunGet(params struct {
|
|||||||
"isNotFound": false,
|
"isNotFound": false,
|
||||||
}
|
}
|
||||||
dbConfigFile := Tea.ConfigFile("api_db.yaml")
|
dbConfigFile := Tea.ConfigFile("api_db.yaml")
|
||||||
data, err := ioutil.ReadFile(dbConfigFile)
|
data, err := os.ReadFile(dbConfigFile)
|
||||||
dbConfigMap["config"] = string(data)
|
dbConfigMap["config"] = string(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dbConfigMap["error"] = err.Error()
|
dbConfigMap["error"] = err.Error()
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ func (this *IndexAction) RunGet(params struct{}) {
|
|||||||
this.Data["error"] = ""
|
this.Data["error"] = ""
|
||||||
|
|
||||||
configFile := Tea.ConfigFile("api_db.yaml")
|
configFile := Tea.ConfigFile("api_db.yaml")
|
||||||
data, err := ioutil.ReadFile(configFile)
|
data, err := os.ReadFile(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Data["error"] = "read config file failed: api_db.yaml: " + err.Error()
|
this.Data["error"] = "read config file failed: api_db.yaml: " + err.Error()
|
||||||
this.Show()
|
this.Show()
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import (
|
|||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -34,7 +34,7 @@ func (this *UpdateAction) RunGet(params struct{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configFile := Tea.ConfigFile("api_db.yaml")
|
configFile := Tea.ConfigFile("api_db.yaml")
|
||||||
data, err := ioutil.ReadFile(configFile)
|
data, err := os.ReadFile(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -144,7 +144,7 @@ dbs:
|
|||||||
models:
|
models:
|
||||||
package: internal/web/models
|
package: internal/web/models
|
||||||
`
|
`
|
||||||
err := ioutil.WriteFile(configFile, []byte(template), 0666)
|
err := os.WriteFile(configFile, []byte(template), 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Fail("保存配置失败:" + err.Error())
|
this.Fail("保存配置失败:" + err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UpdateHTTPSPopupAction struct {
|
type UpdateHTTPSPopupAction struct {
|
||||||
@@ -31,12 +31,12 @@ func (this *UpdateHTTPSPopupAction) RunGet(params struct{}) {
|
|||||||
// 证书
|
// 证书
|
||||||
certConfigs := []*sslconfigs.SSLCertConfig{}
|
certConfigs := []*sslconfigs.SSLCertConfig{}
|
||||||
if len(serverConfig.Https.Cert) > 0 && len(serverConfig.Https.Key) > 0 {
|
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 {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
keyData, err := ioutil.ReadFile(Tea.Root + "/" + serverConfig.Https.Key)
|
keyData, err := os.ReadFile(Tea.Root + "/" + serverConfig.Https.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
@@ -120,11 +120,11 @@ func (this *UpdateHTTPSPopupAction) RunPost(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
this.Fail("保存密钥失败:" + err.Error())
|
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 {
|
if err != nil {
|
||||||
this.Fail("保存证书失败:" + err.Error())
|
this.Fail("保存证书失败:" + err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"github.com/iwind/TeaGo"
|
"github.com/iwind/TeaGo"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"io/ioutil"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
var serverConfigIsChanged = false
|
var serverConfigIsChanged = false
|
||||||
@@ -12,7 +12,7 @@ var serverConfigIsChanged = false
|
|||||||
// 读取当前服务配置
|
// 读取当前服务配置
|
||||||
func loadServerConfig() (*TeaGo.ServerConfig, error) {
|
func loadServerConfig() (*TeaGo.ServerConfig, error) {
|
||||||
configFile := Tea.ConfigFile("server.yaml")
|
configFile := Tea.ConfigFile("server.yaml")
|
||||||
data, err := ioutil.ReadFile(configFile)
|
data, err := os.ReadFile(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ func writeServerConfig(serverConfig *TeaGo.ServerConfig) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(Tea.ConfigFile("server.yaml"), data, 0666)
|
err = os.WriteFile(Tea.ConfigFile("server.yaml"), data, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
stringutil "github.com/iwind/TeaGo/utils/string"
|
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -70,7 +70,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
defer func() {
|
defer func() {
|
||||||
_ = resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
}()
|
}()
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Data["result"] = maps.Map{
|
this.Data["result"] = maps.Map{
|
||||||
"isOk": false,
|
"isOk": false,
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import (
|
|||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/gosock/pkg/gosock"
|
"github.com/iwind/gosock/pkg/gosock"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
@@ -102,7 +101,7 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
this.Fail("生成数据库配置失败:" + err.Error())
|
this.Fail("生成数据库配置失败:" + err.Error())
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(apiNodeDir+"/configs/db.yaml", dbConfigData, 0666)
|
err = os.WriteFile(apiNodeDir+"/configs/db.yaml", dbConfigData, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Fail("保存数据库配置失败:" + err.Error())
|
this.Fail("保存数据库配置失败:" + err.Error())
|
||||||
}
|
}
|
||||||
@@ -116,16 +115,16 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
for _, backupDir := range backupDirs {
|
for _, backupDir := range backupDirs {
|
||||||
stat, err := os.Stat(backupDir)
|
stat, err := os.Stat(backupDir)
|
||||||
if err == nil && stat.IsDir() {
|
if err == nil && stat.IsDir() {
|
||||||
_ = ioutil.WriteFile(backupDir+"/db.yaml", dbConfigData, 0666)
|
_ = os.WriteFile(backupDir+"/db.yaml", dbConfigData, 0666)
|
||||||
} else if err != nil && os.IsNotExist(err) {
|
} else if err != nil && os.IsNotExist(err) {
|
||||||
err = os.Mkdir(backupDir, 0777)
|
err = os.Mkdir(backupDir, 0777)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
_ = ioutil.WriteFile(backupDir+"/db.yaml", dbConfigData, 0666)
|
_ = os.WriteFile(backupDir+"/db.yaml", dbConfigData, 0666)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ioutil.WriteFile(Tea.ConfigFile("/api_db.yaml"), dbConfigData, 0666)
|
err = os.WriteFile(Tea.ConfigFile("/api_db.yaml"), dbConfigData, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Fail("保存数据库配置失败:" + err.Error())
|
this.Fail("保存数据库配置失败:" + err.Error())
|
||||||
}
|
}
|
||||||
@@ -138,11 +137,11 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
for _, backupDir := range backupDirs {
|
for _, backupDir := range backupDirs {
|
||||||
stat, err := os.Stat(backupDir)
|
stat, err := os.Stat(backupDir)
|
||||||
if err == nil && stat.IsDir() {
|
if err == nil && stat.IsDir() {
|
||||||
_ = ioutil.WriteFile(backupDir+"/api_db.yaml", dbConfigData, 0666)
|
_ = os.WriteFile(backupDir+"/api_db.yaml", dbConfigData, 0666)
|
||||||
} else if err != nil && os.IsNotExist(err) {
|
} else if err != nil && os.IsNotExist(err) {
|
||||||
err = os.Mkdir(backupDir, 0777)
|
err = os.Mkdir(backupDir, 0777)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
_ = ioutil.WriteFile(backupDir+"/api_db.yaml", dbConfigData, 0666)
|
_ = os.WriteFile(backupDir+"/api_db.yaml", dbConfigData, 0666)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"io/ioutil"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HideTipAction struct {
|
type HideTipAction struct {
|
||||||
@@ -23,7 +23,7 @@ func (this *HideTipAction) RunPost(params struct {
|
|||||||
// 保存到文件
|
// 保存到文件
|
||||||
tipJSON, err := json.Marshal(tipKeyMap)
|
tipJSON, err := json.Marshal(tipKeyMap)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
_ = ioutil.WriteFile(Tea.ConfigFile(tipConfigFile), tipJSON, 0666)
|
_ = os.WriteFile(Tea.ConfigFile(tipConfigFile), tipJSON, 0666)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/iwind/TeaGo"
|
"github.com/iwind/TeaGo"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ var tipConfigFile = "tip.cache.json"
|
|||||||
func init() {
|
func init() {
|
||||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||||
// 从配置文件中加载已关闭的tips
|
// 从配置文件中加载已关闭的tips
|
||||||
data, err := ioutil.ReadFile(Tea.ConfigFile(tipConfigFile))
|
data, err := os.ReadFile(Tea.ConfigFile(tipConfigFile))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
var m = map[string]bool{}
|
var m = map[string]bool{}
|
||||||
err = json.Unmarshal(data, &m)
|
err = json.Unmarshal(data, &m)
|
||||||
|
|||||||
Reference in New Issue
Block a user