LoginSignup
2
2

More than 5 years have passed since last update.

BurntSushi/tomlを使ってハマったこと

Posted at

omitzeroをつけると読み込めない

自前のコマンドの簡単な設定をtomlで書いていたんですが、omitzeroを付けた場合に、読み込み(decode)の際に、値を読み込んでくれない事態に遭遇しました。

こういう構造体に

type Config struct {
    Text   string `toml:"x_text"`
    Number int    `toml:"number,omitzero"`
}

このファイルを

x_text = "text message."
number = 10

読み込ませてもConfig.Number0になってしまいます。

原因はライブラリのバグですが・・・

結果としてはライブラリのバグでした。

omitzeroを付けなければ、正常に読み込めるため、Issue/PullRequestを探すと、同様の問題に遭遇した方から修正が来てましたが、マージはされていませんでした。

どちらの修正でも、読み込めました。(他のtestも通ります)

https://github.com/BurntSushi/toml/pull/82
https://github.com/BurntSushi/toml/pull/90

このリポジトリ自体が2015/05から更新されていないようなので、自分でforkするかローカルのファイルを編集する、もしくは別のライブラリを探すことが必要です。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2