add PrintJson

This commit is contained in:
yanweidong 2025-08-22 12:15:55 +08:00
parent 63a4653eb2
commit fc72fd123d
1 changed files with 13 additions and 1 deletions

View File

@ -1,6 +1,10 @@
package utils package utils
import ( import (
"bytes"
"encoding/json"
"fmt"
"os"
"strconv" "strconv"
"strings" "strings"
) )
@ -12,7 +16,7 @@ func If(condition bool, trueValue, falseValue interface{}) interface{} {
return falseValue return falseValue
} }
//如果首字母是小写字母, 则变换为大写字母 // 如果首字母是小写字母, 则变换为大写字母
func FirstToUpper(str string) string { func FirstToUpper(str string) string {
if str == "" { if str == "" {
return "" return ""
@ -33,3 +37,11 @@ func ParseParams(in map[string]string) map[string]interface{} {
} }
return out return out
} }
func PrintJson(v any) {
jsonBy, _ := json.Marshal(v)
var out bytes.Buffer
json.Indent(&out, jsonBy, "", "\t")
out.WriteTo(os.Stdout)
fmt.Printf("\n")
}