前言
- 推荐使用常规方法。
- 这种方法说是投机取巧,但是我觉得还是有一定的作用的。
- 此方法只适用于:别的类型转为字符串
正文
- 巧用:fmt.Sprintf()
- 这是函数解释:Sprintf formats according to a format specifier and returns the resulting string.(将格式化的字符串直接进行返回)
- 示范(bool、int…其他类型均可如此使用):
hash := sha256.Sum256([]byte("value"))
hashS := fmt.Sprintf("%x", hash)
// fmt.Println(hashS)
fmt.Printf("%s\n",hashS)
- 常规用法(仅展示一个例子):
hash := sha256.Sum256([]byte("value"))
hashstr := hex.EncodeToString(hash[:])
fmt.Println(hashstr)