瀏覽代碼

codecgen: use real type names if available before constructing name based on kind.

This will allow you perform codegeneration for types like:

  type Test struct {
    Tests Tests
  }
  type Tests []*Test

Fixes #68
Ugorji Nwoke 10 年之前
父節點
當前提交
7d9b80c277
共有 1 個文件被更改,包括 6 次插入0 次删除
  1. 6 0
      codec/gen.go

+ 6 - 0
codec/gen.go

@@ -1388,6 +1388,9 @@ func genTypeName(t reflect.Type, tRef reflect.Type) (n string) {
 		ptrPfx += "*"
 		t = t.Elem()
 	}
+	if tn := t.Name(); tn != "" {
+		return ptrPfx + tn
+	}
 	switch t.Kind() {
 	case reflect.Map:
 		return ptrPfx + "map[" + genTypeName(t.Key(), tRef) + "]" + genTypeName(t.Elem(), tRef)
@@ -1412,6 +1415,9 @@ func genMethodNameT(t reflect.Type, tRef reflect.Type) (n string) {
 		ptrPfx += "Ptrto"
 		t = t.Elem()
 	}
+	if tn := t.Name(); tn != "" {
+		return ptrPfx + tn
+	}
 	switch t.Kind() {
 	case reflect.Map:
 		return ptrPfx + "Map" + genMethodNameT(t.Key(), tRef) + genMethodNameT(t.Elem(), tRef)