Denmaseno 8 years ago
parent
commit
503539ab57
2 changed files with 30 additions and 19 deletions
  1. 30 0
      json.go
  2. 0 19
      util.go

+ 30 - 0
json.go

@@ -0,0 +1,30 @@
+package util
+
+import "encoding/json"
+
+// JSONPrettyPrint func
+func JSONPrettyPrint(v interface{}) string {
+	if bb, err := json.MarshalIndent(v, "", "   "); err != nil {
+		panic(err)
+	} else {
+		return string(bb)
+	}
+}
+
+//
+// // JSONMarshal func
+// func JSONMarshal(w io.Writer, v interface{}) {
+// 	if d, err := json.Marshal(v); err == nil {
+// 		w.Write(d)
+// 	} else {
+// 		panic(err)
+// 	}
+// }
+//
+// // JSONUnmarshal func
+// func JSONUnmarshal(b []byte, v interface{}) interface{} {
+// 	if err := json.Unmarshal(b, v); err != nil {
+// 		panic(err)
+// 	}
+// 	return v
+// }

+ 0 - 19
util.go

@@ -3,9 +3,7 @@ package util
 import (
 	"crypto/rsa"
 	"encoding/binary"
-	"encoding/json"
 	"fmt"
-	"io"
 )
 
 // Signer interface
@@ -41,23 +39,6 @@ func UintToBytes(v uint) []byte {
 	return bb
 }
 
-// JSONMarshal func
-func JSONMarshal(w io.Writer, v interface{}) {
-	if d, err := json.Marshal(v); err == nil {
-		w.Write(d)
-	} else {
-		panic(err)
-	}
-}
-
-// JSONUnmarshal func
-func JSONUnmarshal(b []byte, v interface{}) interface{} {
-	if err := json.Unmarshal(b, v); err != nil {
-		panic(err)
-	}
-	return v
-}
-
 // InStringSlice func
 func InStringSlice(v string, list ...string) bool {
 	for _, vl := range list {