重新整理思路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
import "fmt"
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)
}
}