1
0
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:
小旭 2019-11-03 17:43:16 +08:00
parent 0662113a26
commit b212f69b36
4 changed files with 13 additions and 4 deletions

View File

@ -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()))

View File

@ -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()))

View File

@ -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 {

View File

@ -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
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 {