13 lines
285 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utils
import "encoding/json"
// MustJSONString 把对象转换成 JSON失败时返回调用方指定的回退字符串。
func MustJSONString(value any, fallback string) string {
raw, err := json.Marshal(value)
if err != nil {
return fallback
}
return string(raw)
}