mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-02 16:28:39 +08:00
chore: coding style (#2120)
This commit is contained in:
parent
96acf1f5a6
commit
1c09db6d5d
@ -65,7 +65,7 @@ func Test_apiFormatReader_issue1721(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
filename := path.Join(subDir, "bar.api")
|
filename := path.Join(subDir, "bar.api")
|
||||||
err = ioutil.WriteFile(filename, []byte(fmt.Sprintf(`import "%s"`, importedFilename)), 0644)
|
err = ioutil.WriteFile(filename, []byte(fmt.Sprintf(`import "%s"`, importedFilename)), 0o644)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
f, err := os.Open(filename)
|
f, err := os.Open(filename)
|
||||||
|
@ -60,7 +60,8 @@ func genHandler(dir, rootPkg string, cfg *config.Config, group spec.Group, route
|
|||||||
}
|
}
|
||||||
|
|
||||||
func doGenToFile(dir, handler string, cfg *config.Config, group spec.Group,
|
func doGenToFile(dir, handler string, cfg *config.Config, group spec.Group,
|
||||||
route spec.Route, handleObj handlerInfo) error {
|
route spec.Route, handleObj handlerInfo,
|
||||||
|
) error {
|
||||||
filename, err := format.FileNamingFormat(cfg.NamingFormat, handler)
|
filename, err := format.FileNamingFormat(cfg.NamingFormat, handler)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -254,7 +254,6 @@ func (p *Parser) storeVerificationInfo(api *Api) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) valid(nestedApi *Api) error {
|
func (p *Parser) valid(nestedApi *Api) error {
|
||||||
|
|
||||||
if p.syntax != nil && nestedApi.Syntax != nil {
|
if p.syntax != nil && nestedApi.Syntax != nil {
|
||||||
if p.syntax.Version.Text() != nestedApi.Syntax.Version.Text() {
|
if p.syntax.Version.Text() != nestedApi.Syntax.Version.Text() {
|
||||||
syntaxToken := nestedApi.Syntax.Syntax
|
syntaxToken := nestedApi.Syntax.Syntax
|
||||||
|
@ -25,13 +25,13 @@ func Test_ImportCycle(t *testing.T) {
|
|||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
mainPath := filepath.Join(dir, mainFilename)
|
mainPath := filepath.Join(dir, mainFilename)
|
||||||
err = ioutil.WriteFile(mainPath, []byte(mainSrc), 0777)
|
err = ioutil.WriteFile(mainPath, []byte(mainSrc), 0o777)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
subAPath := filepath.Join(dir, subAFilename)
|
subAPath := filepath.Join(dir, subAFilename)
|
||||||
err = ioutil.WriteFile(subAPath, []byte(subASrc), 0777)
|
err = ioutil.WriteFile(subAPath, []byte(subASrc), 0o777)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
subBPath := filepath.Join(dir, subBFilename)
|
subBPath := filepath.Join(dir, subBFilename)
|
||||||
err = ioutil.WriteFile(subBPath, []byte(subBSrc), 0777)
|
err = ioutil.WriteFile(subBPath, []byte(subBSrc), 0o777)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = NewParser().Parse(mainPath)
|
_, err = NewParser().Parse(mainPath)
|
||||||
@ -55,13 +55,13 @@ func Test_MultiImportedShouldAllowed(t *testing.T) {
|
|||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
mainPath := filepath.Join(dir, mainFilename)
|
mainPath := filepath.Join(dir, mainFilename)
|
||||||
err = ioutil.WriteFile(mainPath, []byte(mainSrc), 0777)
|
err = ioutil.WriteFile(mainPath, []byte(mainSrc), 0o777)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
subAPath := filepath.Join(dir, subAFilename)
|
subAPath := filepath.Join(dir, subAFilename)
|
||||||
err = ioutil.WriteFile(subAPath, []byte(subASrc), 0777)
|
err = ioutil.WriteFile(subAPath, []byte(subASrc), 0o777)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
subBPath := filepath.Join(dir, subBFilename)
|
subBPath := filepath.Join(dir, subBFilename)
|
||||||
err = ioutil.WriteFile(subBPath, []byte(subBSrc), 0777)
|
err = ioutil.WriteFile(subBPath, []byte(subBSrc), 0o777)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = NewParser().Parse(mainPath)
|
_, err = NewParser().Parse(mainPath)
|
||||||
@ -84,13 +84,13 @@ func Test_RedundantDeclarationShouldNotBeAllowed(t *testing.T) {
|
|||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
mainPath := filepath.Join(dir, mainFilename)
|
mainPath := filepath.Join(dir, mainFilename)
|
||||||
err = ioutil.WriteFile(mainPath, []byte(mainSrc), 0777)
|
err = ioutil.WriteFile(mainPath, []byte(mainSrc), 0o777)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
subAPath := filepath.Join(dir, subAFilename)
|
subAPath := filepath.Join(dir, subAFilename)
|
||||||
err = ioutil.WriteFile(subAPath, []byte(subASrc), 0777)
|
err = ioutil.WriteFile(subAPath, []byte(subASrc), 0o777)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
subBPath := filepath.Join(dir, subBFilename)
|
subBPath := filepath.Join(dir, subBFilename)
|
||||||
err = ioutil.WriteFile(subBPath, []byte(subBSrc), 0777)
|
err = ioutil.WriteFile(subBPath, []byte(subBSrc), 0o777)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = NewParser().Parse(mainPath)
|
_, err = NewParser().Parse(mainPath)
|
||||||
|
@ -49,5 +49,4 @@ func needShow1_3_4(dir, style string) (bool, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,8 @@ func (g *defaultGenerator) createFile(modelList map[string]*codeTuple) error {
|
|||||||
|
|
||||||
// ret1: key-table name,value-code
|
// ret1: key-table name,value-code
|
||||||
func (g *defaultGenerator) genFromDDL(filename string, withCache bool, database string) (
|
func (g *defaultGenerator) genFromDDL(filename string, withCache bool, database string) (
|
||||||
map[string]*codeTuple, error) {
|
map[string]*codeTuple, error,
|
||||||
|
) {
|
||||||
m := make(map[string]*codeTuple)
|
m := make(map[string]*codeTuple)
|
||||||
tables, err := parser.Parse(filename, database)
|
tables, err := parser.Parse(filename, database)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -131,12 +131,12 @@ func Test_genPublicModel(t *testing.T) {
|
|||||||
var err error
|
var err error
|
||||||
dir := pathx.MustTempDir()
|
dir := pathx.MustTempDir()
|
||||||
modelDir := path.Join(dir, "model")
|
modelDir := path.Join(dir, "model")
|
||||||
err = os.MkdirAll(modelDir, 0777)
|
err = os.MkdirAll(modelDir, 0o777)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
modelFilename := filepath.Join(modelDir, "foo.sql")
|
modelFilename := filepath.Join(modelDir, "foo.sql")
|
||||||
err = ioutil.WriteFile(modelFilename, []byte(source), 0777)
|
err = ioutil.WriteFile(modelFilename, []byte(source), 0o777)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
g, err := NewDefaultGenerator(modelDir, &config.Config{
|
g, err := NewDefaultGenerator(modelDir, &config.Config{
|
||||||
|
@ -12,9 +12,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func genUpdate(table Table, withCache, postgreSql bool) (
|
func genUpdate(table Table, withCache, postgreSql bool) (
|
||||||
string, string, error) {
|
string, string, error,
|
||||||
|
) {
|
||||||
expressionValues := make([]string, 0)
|
expressionValues := make([]string, 0)
|
||||||
var pkg = "data."
|
pkg := "data."
|
||||||
if table.ContainsUniqueCacheKey {
|
if table.ContainsUniqueCacheKey {
|
||||||
pkg = "newData."
|
pkg = "newData."
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ func initRPCProto() error {
|
|||||||
|
|
||||||
protoFilename := filepath.Join(zrpcWorkDir, protoName)
|
protoFilename := filepath.Join(zrpcWorkDir, protoName)
|
||||||
rpcBytes := []byte(protocContent)
|
rpcBytes := []byte(protocContent)
|
||||||
return ioutil.WriteFile(protoFilename, rpcBytes, 0666)
|
return ioutil.WriteFile(protoFilename, rpcBytes, 0o666)
|
||||||
}
|
}
|
||||||
|
|
||||||
type micro struct{}
|
type micro struct{}
|
||||||
@ -55,7 +55,7 @@ func (m micro) mustStartRPCProject() {
|
|||||||
arg := "goctl rpc protoc " + protoName + " --go_out=. --go-grpc_out=. --zrpc_out=. --verbose"
|
arg := "goctl rpc protoc " + protoName + " --go_out=. --go-grpc_out=. --zrpc_out=. --verbose"
|
||||||
execCommand(zrpcWorkDir, arg)
|
execCommand(zrpcWorkDir, arg)
|
||||||
etcFile := filepath.Join(zrpcWorkDir, "etc", "greet.yaml")
|
etcFile := filepath.Join(zrpcWorkDir, "etc", "greet.yaml")
|
||||||
logx.Must(ioutil.WriteFile(etcFile, []byte(rpcEtcContent), 0666))
|
logx.Must(ioutil.WriteFile(etcFile, []byte(rpcEtcContent), 0o666))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m micro) start() {
|
func (m micro) start() {
|
||||||
|
@ -35,7 +35,7 @@ func initAPIFlags() error {
|
|||||||
|
|
||||||
apiFilename := filepath.Join(apiWorkDir, "greet.api")
|
apiFilename := filepath.Join(apiWorkDir, "greet.api")
|
||||||
apiBytes := []byte(apiContent)
|
apiBytes := []byte(apiContent)
|
||||||
if err := ioutil.WriteFile(apiFilename, apiBytes, 0666); err != nil {
|
if err := ioutil.WriteFile(apiFilename, apiBytes, 0o666); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ func (m mono) createAPIProject() {
|
|||||||
log.Debug(">> Generating quickstart api project...")
|
log.Debug(">> Generating quickstart api project...")
|
||||||
logx.Must(gogen.GoCommand(nil, nil))
|
logx.Must(gogen.GoCommand(nil, nil))
|
||||||
etcFile := filepath.Join(apiWorkDir, "etc", "greet.yaml")
|
etcFile := filepath.Join(apiWorkDir, "etc", "greet.yaml")
|
||||||
logx.Must(ioutil.WriteFile(etcFile, []byte(apiEtcContent), 0666))
|
logx.Must(ioutil.WriteFile(etcFile, []byte(apiEtcContent), 0o666))
|
||||||
logicFile := filepath.Join(apiWorkDir, "internal", "logic", "pinglogic.go")
|
logicFile := filepath.Join(apiWorkDir, "internal", "logic", "pinglogic.go")
|
||||||
svcFile := filepath.Join(apiWorkDir, "internal", "svc", "servicecontext.go")
|
svcFile := filepath.Join(apiWorkDir, "internal", "svc", "servicecontext.go")
|
||||||
configPath := filepath.Join(apiWorkDir, "internal", "config")
|
configPath := filepath.Join(apiWorkDir, "internal", "config")
|
||||||
|
@ -20,7 +20,7 @@ func goModTidy(dir string) int {
|
|||||||
return execCommand(dir, "go mod tidy", prepareGoProxyEnv()...)
|
return execCommand(dir, "go mod tidy", prepareGoProxyEnv()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func execCommand(dir string, arg string, envArgs ...string) int {
|
func execCommand(dir, arg string, envArgs ...string) int {
|
||||||
cmd := exec.Command("sh", "-c", arg)
|
cmd := exec.Command("sh", "-c", arg)
|
||||||
if runtime.GOOS == vars.OsWindows {
|
if runtime.GOOS == vars.OsWindows {
|
||||||
cmd = exec.Command("cmd.exe", "/c", arg)
|
cmd = exec.Command("cmd.exe", "/c", arg)
|
||||||
|
Loading…
Reference in New Issue
Block a user