golang 每日一库(1)

发布时间 2024-01-08 11:40:10作者: haonan071

mapstructure

转载: https://www.cnblogs.com/shix0909/p/15655432.html

作用:
用于将通用的map[string]interface{}解码到对应的 Go 结构体中,或者执行相反的操作。很多时候,解析来自多种源头的数据流时,我们一般事先并不知道他们对应的具体类型。只有读取到一些字段之后才能做出判断。这时,我们可以先使用标准的encoding/json库将数据解码为map[string]interface{}类型,然后根据标识字段利用mapstructure库转为相应的 Go 结构体以便使用。

mkdir mapstructure && cd mapstructure
go mod init github.com/sixinshuier/mapstructure

# 下载库
go get github.com/mitchellh/mapstructure

配置文件工具

转载https://www.jianshu.com/p/f826d2cc361b
一个支持 yaml、json、toml、shell 的配置文件工具
github.com/jinzhu/configor