Denmaseno 8 年之前
父节点
当前提交
a12fc5a941
共有 2 个文件被更改,包括 13 次插入1 次删除
  1. 10 1
      dump.go
  2. 3 0
      dump_test.go

+ 10 - 1
dump.go

@@ -2,6 +2,7 @@ package util
 
 import (
 	"bytes"
+	"crypto/rsa"
 	"fmt"
 	"io"
 	"reflect"
@@ -59,8 +60,16 @@ func fdump(w io.Writer, rx int, rd int, tab string, value reflect.Value) {
 				return
 			}
 		}
+		if value.Type() == reflect.TypeOf(rsa.PublicKey{}) {
+			fmt.Fprintf(w, "- /* Type:%s */", value.Type())
+			return
+		}
+		if value.Type() == reflect.TypeOf(rsa.PrivateKey{}) {
+			fmt.Fprintf(w, "- /* Type:%s */", value.Type())
+			return
+		}
 		ntab := tab + tabSpace
-		fmt.Fprintf(w, "{ /* Type:%s */", value.Type().String())
+		fmt.Fprintf(w, "{ /* Type:%v:%s-%s */", value.CanInterface(), value.Kind().String(), value.Type().String())
 		il := value.NumField()
 		for i, j := 0, 0; i < il && i < MaxFieldLen; i++ {
 			tf := value.Type().Field(i)

+ 3 - 0
dump_test.go

@@ -1,6 +1,7 @@
 package util
 
 import (
+	"crypto/rsa"
 	"fmt"
 	"testing"
 	"time"
@@ -13,6 +14,7 @@ type Struct1 struct {
 	Config    map[string]*Address
 	Age       uint
 	Timestamp time.Time
+	key       *rsa.PublicKey
 }
 
 type Address struct {
@@ -37,6 +39,7 @@ func TestDump(t *testing.T) {
 		config,
 		17,
 		time.Now(),
+		&KeyRSA().PublicKey,
 	}))
 	t.Logf("fmt.Sprintf %s", fmt.Sprintf("HERE\n%v", &Address{"seno", "solo"}))
 }