| 167 | } |
| 168 | |
| 169 | func (c *Config) write(section string, lineNum int, b *bytes.Buffer) error { |
| 170 | if b.Len() <= 0 { |
| 171 | return nil |
| 172 | } |
| 173 | |
| 174 | optionVal := bytes.SplitN(b.Bytes(), []byte{'='}, 2) |
| 175 | if len(optionVal) != 2 { |
| 176 | return fmt.Errorf("parse the content error : line %d , %s = ? ", lineNum, optionVal[0]) |
| 177 | } |
| 178 | option := bytes.TrimSpace(optionVal[0]) |
| 179 | value := bytes.TrimSpace(optionVal[1]) |
| 180 | c.AddConfig(section, string(option), string(value)) |
| 181 | |
| 182 | // flush buffer after adding |
| 183 | b.Reset() |
| 184 | |
| 185 | return nil |
| 186 | } |
| 187 | |
| 188 | // Bool lookups up the value using the provided key and converts the value to a bool. |
| 189 | func (c *Config) Bool(key string) (bool, error) { |