Skip to content

Commit 8a25434

Browse files
committed
适配UTF-8 with BOM编码配置文件
1 parent fe9db17 commit 8a25434

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

config/config.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ func GetConfig() *Config {
3030
if err != nil {
3131
log.Fatalln(err)
3232
}
33-
_, err = toml.Decode(string(tomlData), &conf)
33+
tomlStr := string(tomlData)
34+
// 检测编码是否为UTF-8 with BOM
35+
if tomlStr[0] == 0xEF && tomlStr[1] == 0xBB && tomlStr[2] == 0xBF {
36+
tomlStr = tomlStr[3:]
37+
}
38+
_, err = toml.Decode(tomlStr, &conf)
3439
if err != nil {
3540
log.Fatalln("配置文件错误:", err)
3641
}

0 commit comments

Comments
 (0)