重新整理思路2

This commit is contained in:
qwe
2026-05-21 07:39:35 +08:00
parent f62fd46939
commit 5ceca47d39
11 changed files with 6 additions and 132 deletions

View File

@@ -1,16 +1,4 @@
package main package main
import "fmt"
func main() { func main() {
app, err := getApplication()
if err != nil {
fmt.Println("应用初始化失败")
panic(err)
}
err = app.Start()
if err != nil {
fmt.Println("应用启动失败")
panic(err)
}
} }

View File

@@ -1,9 +0,0 @@
package tool
// Karmaforge 因果熔炉
// 这个函数会被引用,并且最终被代码生成所重写
func Karmaforge[T any](params ...any) *T {
panic("在使用因果熔炉之前,需要执行仪式")
// var result T
// return &result
}

View File

@@ -1 +0,0 @@
package lab

View File

@@ -1,5 +0,0 @@
package lab
type Animal interface {
sound() string
}

View File

@@ -1,3 +0,0 @@
package lab
func main() {}

View File

@@ -1,21 +0,0 @@
package pasture
type Dog struct {
lines string
weapon string
}
func (d *Dog) Sound() string {
return d.lines
}
func (d *Dog) Dangers() bool {
if len(d.weapon) == 0 {
return false
}
return true
}
func NewDog(line string) *Dog {
return &Dog{lines: line}
}

View File

@@ -1,13 +0,0 @@
package pasture
type Sheep struct {
lines string
}
func (s *Sheep) Sound() string {
return s.lines
}
func NewSheep(line string) *Sheep {
return &Sheep{lines: line}
}

View File

@@ -1,59 +0,0 @@
package tool
import (
"fmt"
"go/types"
"os"
"path/filepath"
"strings"
"golang.org/x/tools/go/packages"
)
func main() {
pwd, err := os.Getwd()
if err != nil {
fmt.Println("无法获取当前工作目录")
panic(err)
}
sep := string(filepath.Separator)
s := strings.Split(pwd, sep)
var project string
for i := len(s); i > 0; i-- {
base := strings.Join(s[:i], sep)
module := filepath.Join(base, "go.mod")
_, err := os.Stat(module)
if err == nil {
project = module
break
}
}
if project == "" {
panic("没有找到 go.mod ,请检查是否在 module 中调用程序")
}
project = filepath.Dir(project)
fmt.Println("当前寻根目录 " + project)
pkgs, err := packages.Load(&packages.Config{
Mode: packages.NeedName | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedSyntax | packages.NeedDeps,
Tests: false,
}, filepath.Join(project, "..."))
if err != nil {
fmt.Println("解析项目失败")
panic(err)
}
for _, pkg := range pkgs {
top := pkg.Types.Scope()
funcs := []*types.Func{}
for _, name := range top.Names() {
obj := top.Lookup(name)
if !strings.HasSuffix(obj.Name(), "Provider") {
continue
}
fun, ok := obj.(*types.Func)
if ok {
funcs = append(funcs, fun)
}
}
fmt.Println(pkg.Name)
}
}

View File

@@ -1,14 +1,15 @@
package main package main
import ( import (
"Crimson-Gatekeeper/internal/common" "Crimson-Gatekeeper/internal/database"
"Crimson-Gatekeeper/internal/utils"
"gorm.io/gen" "gorm.io/gen"
) )
func main() { func main() {
client, clean, _ := common.GetDataBaseClient() client, err := database.GetDataBaseClient()
defer clean() utils.PaincEro(err, "数据库链接失败")
g := gen.NewGenerator(gen.Config{ g := gen.NewGenerator(gen.Config{
OutPath: "./internal/query", OutPath: "./internal/query",
ModelPkgPath: "./internal/model", ModelPkgPath: "./internal/model",

View File

@@ -21,9 +21,9 @@ type Cfg struct {
port string port string
passwd string passwd string
connectTimeout int connectTimeout int
ssh bool sshPoint string
} }
ssh struct { sshPoint map[string]struct {
host string host string
port string port string
user string user string
@@ -33,10 +33,6 @@ type Cfg struct {
} }
} }
func (c *Cfg) getDbParam() {
}
func GetCfg() *Cfg { func GetCfg() *Cfg {
pwd, err := os.Getwd() pwd, err := os.Getwd()
utils.PaincEro(err, "获取当前工作目录失败") utils.PaincEro(err, "获取当前工作目录失败")