Repository: zeromicro/go-zero
Pull request #3106 (2023-04-08 12:44:41)

chore: coding style

codecov[bot]: ## [Codecov](https://codecov.io/gh/zeromicro/go-zero/pull/3106?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#3106](https://codecov.io/gh/zeromicro/go-zero/pull/3106?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (e59d1b3) into [master](https://codecov.io/gh/zeromicro/go-zero/commit/2e6402f4b57895f1ef3c2e0f1f0d6a1eaf1e93ef?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (2e6402f) will **increase** coverage by `0.01%`.
> The diff coverage is `n/a`.


[see 3 files with indirect coverage changes](https://codecov.io/gh/zeromicro/go-zero/pull/3106/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)


Patch:
diff --git a/tools/goctl/rpc/generator/gencall.go b/tools/goctl/rpc/generator/gencall.go
index d5e93e9f..060877cd 100644
--- a/tools/goctl/rpc/generator/gencall.go
+++ b/tools/goctl/rpc/generator/gencall.go
@@ -108,7 +108,7 @@ func (g *Generator) genCallGroup(ctx DirContext, proto parser.Proto, cfg *conf.C
 			"name":           callFilename,
 			"alias":          strings.Join(aliasKeys, pathx.NL),
 			"head":           head,
-			"filePackage":    dir.Base,
+			"filePackage":    childDir,
 			"pbPackage":      pbPackage,
 			"protoGoPackage": protoGoPackage,
 			"serviceName":    serviceName,


Test patch:
diff --git a/core/mapping/unmarshaler_test.go b/core/mapping/unmarshaler_test.go
index 6d373444..08c5b834 100644
--- a/core/mapping/unmarshaler_test.go
+++ b/core/mapping/unmarshaler_test.go
@@ -12,7 +12,6 @@ import (
 
 	"github.com/google/uuid"
 	"github.com/stretchr/testify/assert"
-
 	"github.com/zeromicro/go-zero/core/stringx"
 )
 
@@ -4332,6 +4331,97 @@ func TestUnmarshalOnlyPublicVariables(t *testing.T) {
 	}
 }
 
+func TestFillDefaultUnmarshal(t *testing.T) {
+	fillDefaultUnmarshal := NewUnmarshaler(jsonTagKey, WithDefault())
+	t.Run("nil", func(t *testing.T) {
+		type St struct{}
+		err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, St{})
+		assert.Error(t, err)
+	})
+
+	t.Run("not nil", func(t *testing.T) {
+		type St struct{}
+		err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &St{})
+		assert.NoError(t, err)
+	})
+
+	t.Run("default", func(t *testing.T) {
+		type St struct {
+			A string `json:",default=a"`
+			B string
+		}
+		var st St
+		err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &st)
+		assert.NoError(t, err)
+		assert.Equal(t, "a", st.A)
+	})
+
+	t.Run("env", func(t *testing.T) {
+		type St struct {
+			A string `json:",default=a"`
+			B string
+			C string `json:",env=TEST_C"`
+		}
+		t.Setenv("TEST_C", "c")
+
+		var st St
+		err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &st)
+		assert.NoError(t, err)
+		assert.Equal(t, "a", st.A)
+		assert.Equal(t, "c", st.C)
+	})
+
+	t.Run("has value", func(t *testing.T) {
+		type St struct {
+			A string `json:",default=a"`
+			B string
+		}
+		var st = St{
+			A: "b",
+		}
+		err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &st)
+		assert.Error(t, err)
+	})
+
+	t.Run("handling struct", func(t *testing.T) {
+		type St struct {
+			A string `json:",default=a"`
+			B string
+		}
+		type St2 struct {
+			St
+			St1   St
+			St3   *St
+			C     string `json:",default=c"`
+			D     string
+			Child *St2
+		}
+		var st2 St2
+		err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &st2)
+		assert.NoError(t, err)
+		assert.Equal(t, "a", st2.St.A)
+		assert.Equal(t, "a", st2.St1.A)
+		assert.Nil(t, st2.St3)
+		assert.Equal(t, "c", st2.C)
+		assert.Nil(t, st2.Child)
+	})
+}
+
+func Test_UnmarshalMap(t *testing.T) {
+	type Customer struct {
+		Names map[int]string `key:"names"`
+	}
+
+	input := map[string]any{
+		"names": map[string]any{
+			"19": "Tom",
+		},
+	}
+
+	var customer Customer
+	assert.ErrorIs(t, UnmarshalKey(input, &customer), errTypeMismatch)
+}
+
 func BenchmarkDefaultValue(b *testing.B) {
 	for i := 0; i < b.N; i++ {
 		var a struct {
@@ -4431,95 +4521,3 @@ func BenchmarkUnmarshal(b *testing.B) {
 		UnmarshalKey(data, &an)
 	}
 }
-
-func TestFillDefaultUnmarshal(t *testing.T) {
-	fillDefaultUnmarshal := NewUnmarshaler(jsonTagKey, WithDefault())
-	t.Run("nil", func(t *testing.T) {
-		type St struct{}
-		err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, St{})
-		assert.Error(t, err)
-	})
-
-	t.Run("not nil", func(t *testing.T) {
-		type St struct{}
-		err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &St{})
-		assert.NoError(t, err)
-	})
-
-	t.Run("default", func(t *testing.T) {
-		type St struct {
-			A string `json:",default=a"`
-			B string
-		}
-		var st St
-		err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &st)
-		assert.NoError(t, err)
-		assert.Equal(t, "a", st.A)
-	})
-
-	t.Run("env", func(t *testing.T) {
-		type St struct {
-			A string `json:",default=a"`
-			B string
-			C string `json:",env=TEST_C"`
-		}
-		t.Setenv("TEST_C", "c")
-
-		var st St
-		err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &st)
-		assert.NoError(t, err)
-		assert.Equal(t, "a", st.A)
-		assert.Equal(t, "c", st.C)
-	})
-
-	t.Run("has value", func(t *testing.T) {
-		type St struct {
-			A string `json:",default=a"`
-			B string
-		}
-		var st = St{
-			A: "b",
-		}
-		err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &st)
-		assert.Error(t, err)
-	})
-
-	t.Run("handling struct", func(t *testing.T) {
-		type St struct {
-			A string `json:",default=a"`
-			B string
-		}
-		type St2 struct {
-			St
-			St1   St
-			St3   *St
-			C     string `json:",default=c"`
-			D     string
-			Child *St2
-		}
-		var st2 St2
-		err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &st2)
-		assert.NoError(t, err)
-		assert.Equal(t, "a", st2.St.A)
-		assert.Equal(t, "a", st2.St1.A)
-		assert.Nil(t, st2.St3)
-		assert.Equal(t, "c", st2.C)
-		assert.Nil(t, st2.Child)
-	})
-
-}
-
-func Test_UnmarshalMap(t *testing.T) {
-	type Customer struct {
-		Names map[int]string `key:"names"`
-	}
-
-	input := map[string]any{
-		"names": map[string]any{
-			"19": "Tom",
-		},
-	}
-
-	var customer Customer
-	assert.ErrorIs(t, UnmarshalKey(input, &customer), errTypeMismatch)
-}