|
|
@ -2,12 +2,12 @@ package gen
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/rpc/execx"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/rpc/execx"
|
|
|
|
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/rpc/parser"
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/rpc/parser"
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/util"
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/util"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -119,6 +119,8 @@ func (g *defaultRpcGenerator) genShared() error {
|
|
|
|
"types": typeCode,
|
|
|
|
"types": typeCode,
|
|
|
|
}, filename, true)
|
|
|
|
}, filename, true)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_, err = exec.LookPath("mockgen")
|
|
|
|
|
|
|
|
mockGenInstalled := err == nil
|
|
|
|
for _, service := range file.Service {
|
|
|
|
for _, service := range file.Service {
|
|
|
|
filename := filepath.Join(g.Ctx.SharedDir, fmt.Sprintf("%smodel.go", service.Name.Lower()))
|
|
|
|
filename := filepath.Join(g.Ctx.SharedDir, fmt.Sprintf("%smodel.go", service.Name.Lower()))
|
|
|
|
functions, err := g.getFuncs(service)
|
|
|
|
functions, err := g.getFuncs(service)
|
|
|
@ -144,15 +146,13 @@ func (g *defaultRpcGenerator) genShared() error {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if mockgen is already installed, it will generate code of gomock for shared files
|
|
|
|
// if mockgen is already installed, it will generate code of gomock for shared files
|
|
|
|
_, err = exec.LookPath("mockgen")
|
|
|
|
_, err = exec.LookPath("mockgen")
|
|
|
|
if err != nil {
|
|
|
|
if mockGenInstalled {
|
|
|
|
g.Ctx.Warning("warning:mockgen is not found")
|
|
|
|
execx.Run(fmt.Sprintf("go generate %s", filename))
|
|
|
|
} else {
|
|
|
|
|
|
|
|
execx.Run(fmt.Sprintf("cd %s \ngo generate", g.Ctx.SharedDir))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|