第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用 Go 讀取 TOML 文件時(shí)結(jié)果為空

使用 Go 讀取 TOML 文件時(shí)結(jié)果為空

Go
慕碼人2483693 2022-12-19 21:21:18
我正在嘗試用 Go 讀取一個(gè) toml 文件。我不僅希望擁有不同的文件系統(tǒng),filesystem.file而且還希望擁有不同的文件系統(tǒng)filesystem.s3,它們定義了不同的路徑。但它只返回一個(gè)空的 struct {map[file:{map[]}]}。我錯(cuò)過(guò)了什么?我正在使用這個(gè)庫(kù)來(lái)讀取 toml 文件:https ://github.com/BurntSushi/toml文件:[filesystem.file]    [filesystem.file.test]        folder = "tmp/testdata"    [filesystem.file.test2]        folder = "tmp/testdata2"[filesystem.s3]    [filesystem.s3.test]        folder = "s3folder/testdata"我的代碼:package maintype File struct {    Folder string `toml:"folder"`}type FileSystem struct {    File map[string]File `toml:"file"`}type Config struct {    FileSystem  map[string]FileSystem `toml:"filesystem"`}func main() {    var conf Config    _, err := toml.DecodeFile("test.toml", &conf)    if err != nil {        log.Fatalln("Error on loading config: ", err)    }    log.Printf("config: %v", conf)}
查看完整描述

1 回答

?
神不在的星期二

TA貢獻(xiàn)1963條經(jīng)驗(yàn) 獲得超6個(gè)贊

輸入中定義的 TOML 對(duì)應(yīng)于一個(gè)頂級(jí)filesystem結(jié)構(gòu),包含多種類型 iefile等s3。因此定義等效的 Go 結(jié)構(gòu)來(lái)解碼這些結(jié)構(gòu)的正確方法是


type File struct {

    Folder string `toml:"folder"`

}


type FileSystem struct {

    File map[string]File `toml:"file"`

    S3   map[string]File `toml:"s3"`

}


type Config struct {

    FileSystem FileSystem `toml:"filesystem"`

}

https://go.dev/play/p/lfFKVL4_1zx


查看完整回答
反對(duì) 回復(fù) 2022-12-19
  • 1 回答
  • 0 關(guān)注
  • 180 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)