mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-19 21:18:07 +02:00
fixed genproject
This commit is contained in:
parent
0662113a26
commit
b212f69b36
@ -10,6 +10,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
@ -486,7 +487,9 @@ func main() {
|
|||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
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()))
|
options := parse(pkg.NewSource(pkg.SourceText()))
|
||||||
|
@ -516,7 +516,7 @@ func main() {
|
|||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
buf := make([]byte, 64*1024)
|
buf := make([]byte, 64*1024)
|
||||||
buf = buf[:runtime.Stack(buf, false)]
|
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()))
|
options := parse(common.NewSource(common.SourceText()))
|
||||||
|
@ -2,10 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/bilibili/kratos/tool/pkg"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,7 +42,9 @@ func modPath(p string) string {
|
|||||||
dir := filepath.Dir(p)
|
dir := filepath.Dir(p)
|
||||||
for {
|
for {
|
||||||
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
|
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)
|
parent := filepath.Dir(dir)
|
||||||
if dir == parent {
|
if dir == parent {
|
||||||
|
@ -118,7 +118,9 @@ func FormatCode(source string) string {
|
|||||||
// Packages get import packages
|
// Packages get import packages
|
||||||
func (s *Source) Packages(f *ast.Field) (res []string) {
|
func (s *Source) Packages(f *ast.Field) (res []string) {
|
||||||
fs := f.Type.(*ast.FuncType).Params.List
|
fs := f.Type.(*ast.FuncType).Params.List
|
||||||
|
if f.Type.(*ast.FuncType).Results != nil {
|
||||||
fs = append(fs, f.Type.(*ast.FuncType).Results.List...)
|
fs = append(fs, f.Type.(*ast.FuncType).Results.List...)
|
||||||
|
}
|
||||||
var types []string
|
var types []string
|
||||||
resMap := make(map[string]bool)
|
resMap := make(map[string]bool)
|
||||||
for _, field := range fs {
|
for _, field := range fs {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user