重新整理思路

# Conflicts:
#	srv/cmd/gatekeeper/wire.go
#	srv/internal/application/appliceation.go
This commit is contained in:
qwe
2026-05-21 00:10:02 +08:00
parent c7601ed174
commit f62fd46939
10 changed files with 120 additions and 70 deletions

View File

@@ -35,8 +35,11 @@ func (app *Application) Stop() {
}
}
func NewApplication(ct Ctrl, p *sql.DB) *Application {
func NewApplication(cs []Ctrl, p *sql.DB) *Application {
route := gin.Default()
for _, ctrl := range cs {
ctrl.RegisterRoutes(route)
}
srv := &http.Server{
Addr: ":8443",
Handler: route,

View File

@@ -0,0 +1,63 @@
package parse
import (
"fmt"
"os"
"path"
"strings"
"Crimson-Gatekeeper/internal/utils"
"gopkg.in/yaml.v3"
)
type Cfg struct {
server struct {
port string
database struct {
host string
user string
dbname string
sslmode string
port string
passwd string
connectTimeout int
ssh bool
}
ssh struct {
host string
port string
user string
passwd string
keyPath string
}
}
}
func (c *Cfg) getDbParam() {
}
func GetCfg() *Cfg {
pwd, err := os.Getwd()
utils.PaincEro(err, "获取当前工作目录失败")
dirs, err := os.ReadDir(pwd)
utils.PaincEro(err, "获取目录文件失败")
var data []byte
for _, item := range dirs {
isyaml := strings.HasSuffix(item.Name(), ".yaml")
if isyaml {
filePath := path.Join(pwd, item.Name())
data, err = os.ReadFile(filePath)
utils.PaincEro(err, "读取配置文件失败")
break
}
}
if data == nil {
fmt.Println("没有找到配置文件,启动失败")
panic("没有找到配置文件,进程终止")
}
cfg := &Cfg{}
err = yaml.Unmarshal(data, cfg)
utils.PaincEro(err, "解析配置文件失败")
return cfg
}

View File

@@ -0,0 +1 @@
package server

View File

@@ -0,0 +1,10 @@
package utils
import "fmt"
func PaincEro(err error, msg string) {
if err != nil {
fmt.Println(msg)
panic(err)
}
}