ini.go
func (c *Config) Write(out io.Writer) error {
	for _, cmt := range c.comments {
		fmt.Fprintln(out, "; "+cmt)
	}
	if len(c.comments) > 0 {
		fmt.Fprintln(out)
	}

	for _, sect := range c.sections {
		fmt.Fprintf(out, "[%s]\n", sect.name)
		for _, cmt := range sect.comments {
			fmt.Fprintln(out, "; "+cmt)
		}
		for _, opt := range sect.options {
			val := opt.value
			if len(val) == 0 {
				continue
			}

			// Quote the string if it begins or ends with space
			needsQuoting := val[0] == ' ' || val[len(val)-1] == ' '

			if !needsQuoting {
				// Quote the string if it contains any unprintable characters
				for _, r := range val {
					if !strconv.IsPrint(r) {
						needsQuoting = true
						break
					}
				}
			}

			if needsQuoting {
				val = strconv.Quote(val)
			}

			fmt.Fprintf(out, "%s=%s\n", opt.name, val)
		}
		fmt.Fprintln(out)
	}
	return nil
}
func (c *Config) Write(out io.Writer) error {
	for _, cmt := range c.comments {
		fmt.Fprintln(out, "; "+cmt)
	}
	if len(c.comments) > 0 {
		fmt.Fprintln(out)
	}

	for _, sect := range c.sections {
		fmt.Fprintf(out, "[%s]\n", sect.name)
		for _, cmt := range sect.comments {
			fmt.Fprintln(out, "; "+cmt)
		}
		for _, opt := range sect.options {
			val := opt.value
			if len(val) == 0 {
				continue
			}

			// Quote the string if it begins or ends with space
			needsQuoting := val[0] == ' ' || val[len(val)-1] == ' '

			if !needsQuoting {
				// Quote the string if it contains any unprintable characters
				for _, r := range val {
					if !strconv.IsPrint(r) {
						needsQuoting = true
						break
					}
				}
			}

			if needsQuoting {
				val = strconv.Quote(val)
			}

			fmt.Fprintf(out, "%s=%s\n", opt.name, val)
		}
		fmt.Fprintln(out)
	}
	return nil
}
// Write writes the sections and options to the io.Writer in INI format.