mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-17 21:07:54 +02:00
fixed genproject
This commit is contained in:
parent
0662113a26
commit
b212f69b36
@ -10,6 +10,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
@ -486,7 +487,9 @@ func main() {
|
||||
log.SetFlags(0)
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
log.Fatalf("程序解析失败, err: %+v", err)
|
||||
buf := make([]byte, 64*1024)
|
||||
buf = buf[:runtime.Stack(buf, false)]
|
||||
log.Fatalf("程序解析失败, err: %+v stack: %s", err, buf)
|
||||
}
|
||||
}()
|
||||
options := parse(pkg.NewSource(pkg.SourceText()))
|
||||
|
@ -516,7 +516,7 @@ func main() {
|
||||
if err := recover(); err != nil {
|
||||
buf := make([]byte, 64*1024)
|
||||
buf = buf[:runtime.Stack(buf, false)]
|
||||
log.Fatalf("程序解析失败, err: %+v stack: %s 请企业微信联系 @wangxu01", err, buf)
|
||||
log.Fatalf("程序解析失败, err: %+v stack: %s", err, buf)
|
||||
}
|
||||
}()
|
||||
options := parse(common.NewSource(common.SourceText()))
|
||||
|
@ -2,10 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/bilibili/kratos/tool/pkg"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -40,7 +42,9 @@ func modPath(p string) string {
|
||||
dir := filepath.Dir(p)
|
||||
for {
|
||||
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
|
||||
return strings.TrimPrefix(filepath.Dir(p), filepath.Dir(dir)+string(os.PathSeparator)) + "/"
|
||||
content, _ := ioutil.ReadFile(filepath.Join(dir, "go.mod"))
|
||||
mod := pkg.RegexpReplace(`module\s+(?P<name>[\S]+)`, string(content), "$name")
|
||||
return fmt.Sprintf("%s/%s/", mod, strings.TrimPrefix(filepath.Dir(p), dir+string(os.PathSeparator)))
|
||||
}
|
||||
parent := filepath.Dir(dir)
|
||||
if dir == parent {
|
||||
|
@ -118,7 +118,9 @@ func FormatCode(source string) string {
|
||||
// Packages get import packages
|
||||
func (s *Source) Packages(f *ast.Field) (res []string) {
|
||||
fs := f.Type.(*ast.FuncType).Params.List
|
||||
fs = append(fs, f.Type.(*ast.FuncType).Results.List...)
|
||||
if f.Type.(*ast.FuncType).Results != nil {
|
||||
fs = append(fs, f.Type.(*ast.FuncType).Results.List...)
|
||||
}
|
||||
var types []string
|
||||
resMap := make(map[string]bool)
|
||||
for _, field := range fs {
|
||||
|
Loading…
x
Reference in New Issue
Block a user