Documentation
¶
Overview ¶
Package confval 读写行式配置文件中的键值项
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Directive 「键 值」,用于 redis、valkey Directive = Codec{Assign: " ", Comments: []string{"#"}} // FTP 「键 值」,pure-ftpd 的配置项必须带值 FTP = Codec{Assign: " ", Comments: []string{"#"}, RequireValue: true} // Properties 「键=值」,用于 kafka、rocketmq Properties = Codec{Delim: "=", Assign: "=", Comments: []string{"#"}} // Nginx 「键 值;」,支持行尾注释 Nginx = Codec{Assign: " ", Terminator: ";", Comments: []string{"#"}, InlineComment: true, RequireValue: true, AppendIndent: " "} // Postgres 「键 = '值'」,支持行尾注释 Postgres = Codec{Delim: "=", Assign: " = ", Quote: "'", Comments: []string{"#"}, InlineComment: true} // INI 「键 = 值」,忽略分组,用于 mysql INI = Codec{Delim: "=", Assign: " = ", Comments: []string{"#", ";"}} // SectionINI 分组感知的 INI,用于 grafana SectionINI = Codec{Delim: "=", Assign: " = ", Comments: []string{"#", ";"}, Sections: true} // PHPINI PHP 的 ini,注释优先使用 ";" PHPINI = Codec{Delim: "=", Assign: " = ", Comments: []string{";", "#"}} // Supervisor 「键=值」,注释同时支持 ";" 与 "#" Supervisor = Codec{Delim: "=", Assign: "=", Comments: []string{";", "#"}} )
各应用配置文件的书写约定
Functions ¶
Types ¶
type Codec ¶
type Codec struct {
// Delim 读取时分隔键与值的字符,空表示按空白切分
Delim string
// Assign 写入时的键值分隔符,如 " "、"="、" = "
Assign string
// Terminator 行尾终止符,如 nginx 的 ";"
Terminator string
// Quote 写入时给值添加的引号,读取时一并去除
Quote string
// Comments 识别为注释的前缀,第一个用于注释掉配置项
Comments []string
// Sections 是否按 [section] 分组匹配
Sections bool
// InlineComment 该格式支持行尾注释
// 仅对确实支持的格式开启:redis.conf 与 java properties 不支持,
// 值里的 "#" 是数据(如密码),误判会损坏配置
InlineComment bool
// RequireValue 匹配时要求该行已带值,用于区分「开关」与「键 值」
RequireValue bool
// AppendIndent 追加新配置项时使用的缩进
AppendIndent string
}
Codec 描述一种行式配置文件的书写约定
Click to show internal directories.
Click to hide internal directories.