2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 10:17:17 +08:00

feat: 将面板配置固定保存

This commit is contained in:
耗子
2024-10-12 18:11:34 +08:00
parent 6ec5ebb18d
commit 3c1c4e92b9
9 changed files with 31 additions and 81 deletions

View File

@@ -2,9 +2,6 @@ package bootstrap
import (
"log"
"os"
"path/filepath"
"strings"
"time"
"github.com/knadh/koanf/parsers/yaml"
@@ -12,26 +9,17 @@ import (
"github.com/knadh/koanf/v2"
"github.com/TheTNB/panel/internal/app"
"github.com/TheTNB/panel/pkg/io"
)
func initConf() {
executable, err := os.Executable()
if err != nil {
log.Fatalf("failed to get executable: %v", err)
}
res, err := filepath.EvalSymlinks(filepath.Dir(executable))
if err != nil {
log.Fatalf("failed to get executable path: %v", err)
}
if isTesting() || isAir() || isDirectlyRun() {
res, err = os.Getwd()
if err != nil {
log.Fatalf("failed to get working directory: %v", err)
}
config := "/usr/local/etc/panel/config.yml"
if !io.Exists(config) {
config = "config.yml"
}
app.Conf = koanf.New(".")
if err = app.Conf.Load(file.Provider(filepath.Join(res, "config/config.yml")), yaml.Parser()); err != nil {
if err := app.Conf.Load(file.Provider(config), yaml.Parser()); err != nil {
log.Fatalf("failed to load config: %v", err)
}
}
@@ -48,32 +36,3 @@ func initGlobal() {
}
time.Local = loc
}
// isTesting checks if the application is running in testing mode.
func isTesting() bool {
for _, arg := range os.Args {
if strings.Contains(arg, "-test.") {
return true
}
}
return false
}
// isAir checks if the application is running using Air.
func isAir() bool {
for _, arg := range os.Args {
if strings.Contains(filepath.ToSlash(arg), "/storage/temp") {
return true
}
}
return false
}
// isDirectlyRun checks if the application is running using go run.
func isDirectlyRun() bool {
executable, _ := os.Executable()
return strings.Contains(filepath.Base(executable), os.TempDir()) ||
(strings.Contains(filepath.ToSlash(executable), "/var/folders") && strings.Contains(filepath.ToSlash(executable), "/T/go-build")) // macOS
}