浏览代码

chore: coding style (#2120)

Kevin Wan 2 年之前
父节点
当前提交
1c09db6d5d

+ 1 - 1
tools/goctl/api/format/format_test.go

@@ -65,7 +65,7 @@ func Test_apiFormatReader_issue1721(t *testing.T) {
 	require.NoError(t, err)
 
 	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)
 
 	f, err := os.Open(filename)

+ 2 - 1
tools/goctl/api/gogen/genhandlers.go

@@ -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,
-	route spec.Route, handleObj handlerInfo) error {
+	route spec.Route, handleObj handlerInfo,
+) error {
 	filename, err := format.FileNamingFormat(cfg.NamingFormat, handler)
 	if err != nil {
 		return err

+ 0 - 1
tools/goctl/api/parser/g4/ast/apiparser.go

@@ -254,7 +254,6 @@ func (p *Parser) storeVerificationInfo(api *Api) {
 }
 
 func (p *Parser) valid(nestedApi *Api) error {
-
 	if p.syntax != nil && nestedApi.Syntax != nil {
 		if p.syntax.Version.Text() != nestedApi.Syntax.Version.Text() {
 			syntaxToken := nestedApi.Syntax.Syntax

+ 9 - 9
tools/goctl/api/parser/g4/ast/apiparser_test.go

@@ -25,13 +25,13 @@ func Test_ImportCycle(t *testing.T) {
 	defer os.RemoveAll(dir)
 
 	mainPath := filepath.Join(dir, mainFilename)
-	err = ioutil.WriteFile(mainPath, []byte(mainSrc), 0777)
+	err = ioutil.WriteFile(mainPath, []byte(mainSrc), 0o777)
 	require.NoError(t, err)
 	subAPath := filepath.Join(dir, subAFilename)
-	err = ioutil.WriteFile(subAPath, []byte(subASrc), 0777)
+	err = ioutil.WriteFile(subAPath, []byte(subASrc), 0o777)
 	require.NoError(t, err)
 	subBPath := filepath.Join(dir, subBFilename)
-	err = ioutil.WriteFile(subBPath, []byte(subBSrc), 0777)
+	err = ioutil.WriteFile(subBPath, []byte(subBSrc), 0o777)
 	require.NoError(t, err)
 
 	_, err = NewParser().Parse(mainPath)
@@ -55,13 +55,13 @@ func Test_MultiImportedShouldAllowed(t *testing.T) {
 	defer os.RemoveAll(dir)
 
 	mainPath := filepath.Join(dir, mainFilename)
-	err = ioutil.WriteFile(mainPath, []byte(mainSrc), 0777)
+	err = ioutil.WriteFile(mainPath, []byte(mainSrc), 0o777)
 	require.NoError(t, err)
 	subAPath := filepath.Join(dir, subAFilename)
-	err = ioutil.WriteFile(subAPath, []byte(subASrc), 0777)
+	err = ioutil.WriteFile(subAPath, []byte(subASrc), 0o777)
 	require.NoError(t, err)
 	subBPath := filepath.Join(dir, subBFilename)
-	err = ioutil.WriteFile(subBPath, []byte(subBSrc), 0777)
+	err = ioutil.WriteFile(subBPath, []byte(subBSrc), 0o777)
 	require.NoError(t, err)
 
 	_, err = NewParser().Parse(mainPath)
@@ -84,13 +84,13 @@ func Test_RedundantDeclarationShouldNotBeAllowed(t *testing.T) {
 	defer os.RemoveAll(dir)
 
 	mainPath := filepath.Join(dir, mainFilename)
-	err = ioutil.WriteFile(mainPath, []byte(mainSrc), 0777)
+	err = ioutil.WriteFile(mainPath, []byte(mainSrc), 0o777)
 	require.NoError(t, err)
 	subAPath := filepath.Join(dir, subAFilename)
-	err = ioutil.WriteFile(subAPath, []byte(subASrc), 0777)
+	err = ioutil.WriteFile(subAPath, []byte(subASrc), 0o777)
 	require.NoError(t, err)
 	subBPath := filepath.Join(dir, subBFilename)
-	err = ioutil.WriteFile(subBPath, []byte(subBSrc), 0777)
+	err = ioutil.WriteFile(subBPath, []byte(subBSrc), 0o777)
 	require.NoError(t, err)
 
 	_, err = NewParser().Parse(mainPath)

+ 0 - 1
tools/goctl/model/sql/command/migrationnotes/v1.3.4.go

@@ -49,5 +49,4 @@ func needShow1_3_4(dir, style string) (bool, error) {
 		}
 	}
 	return false, nil
-
 }

+ 2 - 1
tools/goctl/model/sql/gen/gen.go

@@ -202,7 +202,8 @@ func (g *defaultGenerator) createFile(modelList map[string]*codeTuple) error {
 
 // ret1: key-table name,value-code
 func (g *defaultGenerator) genFromDDL(filename string, withCache bool, database string) (
-	map[string]*codeTuple, error) {
+	map[string]*codeTuple, error,
+) {
 	m := make(map[string]*codeTuple)
 	tables, err := parser.Parse(filename, database)
 	if err != nil {

+ 2 - 2
tools/goctl/model/sql/gen/gen_test.go

@@ -131,12 +131,12 @@ func Test_genPublicModel(t *testing.T) {
 	var err error
 	dir := pathx.MustTempDir()
 	modelDir := path.Join(dir, "model")
-	err = os.MkdirAll(modelDir, 0777)
+	err = os.MkdirAll(modelDir, 0o777)
 	require.NoError(t, err)
 	defer os.RemoveAll(dir)
 
 	modelFilename := filepath.Join(modelDir, "foo.sql")
-	err = ioutil.WriteFile(modelFilename, []byte(source), 0777)
+	err = ioutil.WriteFile(modelFilename, []byte(source), 0o777)
 	require.NoError(t, err)
 
 	g, err := NewDefaultGenerator(modelDir, &config.Config{

+ 3 - 2
tools/goctl/model/sql/gen/update.go

@@ -12,9 +12,10 @@ import (
 )
 
 func genUpdate(table Table, withCache, postgreSql bool) (
-	string, string, error) {
+	string, string, error,
+) {
 	expressionValues := make([]string, 0)
-	var pkg = "data."
+	pkg := "data."
 	if table.ContainsUniqueCacheKey {
 		pkg = "newData."
 	}

+ 2 - 2
tools/goctl/quickstart/micro.go

@@ -38,7 +38,7 @@ func initRPCProto() error {
 
 	protoFilename := filepath.Join(zrpcWorkDir, protoName)
 	rpcBytes := []byte(protocContent)
-	return ioutil.WriteFile(protoFilename, rpcBytes, 0666)
+	return ioutil.WriteFile(protoFilename, rpcBytes, 0o666)
 }
 
 type micro struct{}
@@ -55,7 +55,7 @@ func (m micro) mustStartRPCProject() {
 	arg := "goctl rpc protoc " + protoName + " --go_out=. --go-grpc_out=. --zrpc_out=. --verbose"
 	execCommand(zrpcWorkDir, arg)
 	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() {

+ 2 - 2
tools/goctl/quickstart/mono.go

@@ -35,7 +35,7 @@ func initAPIFlags() error {
 
 	apiFilename := filepath.Join(apiWorkDir, "greet.api")
 	apiBytes := []byte(apiContent)
-	if err := ioutil.WriteFile(apiFilename, apiBytes, 0666); err != nil {
+	if err := ioutil.WriteFile(apiFilename, apiBytes, 0o666); err != nil {
 		return err
 	}
 
@@ -59,7 +59,7 @@ func (m mono) createAPIProject() {
 	log.Debug(">> Generating quickstart api project...")
 	logx.Must(gogen.GoCommand(nil, nil))
 	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")
 	svcFile := filepath.Join(apiWorkDir, "internal", "svc", "servicecontext.go")
 	configPath := filepath.Join(apiWorkDir, "internal", "config")

+ 1 - 1
tools/goctl/quickstart/run.go

@@ -20,7 +20,7 @@ func goModTidy(dir string) int {
 	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)
 	if runtime.GOOS == vars.OsWindows {
 		cmd = exec.Command("cmd.exe", "/c", arg)