// readConfigFile reads the specified configuration file.
// For each line of the form "key value" or "key = value", it sets the flag
// variable named key to a value of value.
readConfigFile reads the specified configuration file.
For each line of the form "key value" or "key = value", it sets the flag
variable named key to a value of value.
// readConfigFile reads the specified configuration file . // For each line of the form " key value " or " key = value " it sets the flag // variable named key to a value of value .
func (c *config) readConfigFile(filename string) error {
	f, err := os.Open(filename)
	if err != nil {
		return fmt.Errorf("could not open %s: %s", filename, err)
	}
	defer f.Close()
	r := bufio.NewReader(f)
	for {
		line, err := r.ReadString('\n')
		if line == "" {
			if err != io.EOF {
				log.Println("Error reading config file:", err)
			}
			break
		}
		line = strings.TrimSpace(line)
		if line == "" || line[0] == '#' {
			continue
		}
		keyEnd := strings.IndexAny(line, " \t=")
		if keyEnd == -1 {
			keyEnd = len(line)
		}
		key := line[:keyEnd]
		line = line[keyEnd:]
		line = strings.TrimSpace(line)
		if line != "" && line[0] == '=' {
			line = strings.TrimSpace(line[1:])
		}
		var value string
		if line == "" {
			value = ""
		} else if line[0] == '"' {
			n, err := fmt.Sscanf(line, "%q", &value)
			if n != 1 || err != nil {
				log.Println("Improperly-quoted value in config file:", line)
			}
		} else {
			sharp := strings.Index(line, "#")
			if sharp != -1 {
				line = strings.TrimSpace(line[:sharp])
			}
			value = line
		}
		err = c.flags.Set(key, value)
		if err != nil {
			log.Println("Could not set", key, "to", value, ":", err)
		}
	}
	return nil
}
func ( c * config ) readConfigFile ( filename string ) error { f , err := os . Open ( filename ) if err != nil { return fmt . Errorf ( " " , filename , err ) } defer f . Close ( ) r := bufio . NewReader ( f ) for { line , err := r . ReadString ( '\n' ) if line == " " { if err != io . EOF { log . Println ( " " , err ) } break } line = strings . TrimSpace ( line ) if line == " " || line [ 0 ] == '#' { continue } keyEnd := strings . IndexAny ( line , " \t " ) if keyEnd == - 1 { keyEnd = len ( line ) } key := line [ : keyEnd ] line = line [ keyEnd : ] line = strings . TrimSpace ( line ) if line != " " && line [ 0 ] == '=' { line = strings . TrimSpace ( line [ 1 : ] ) } var value string if line == " " { value = " " } else if line [ 0 ] == '"' { n , err := fmt . Sscanf ( line , " " , & value ) if n != 1 || err != nil { log . Println ( " " , line ) } } else { sharp := strings . Index ( line , " " ) if sharp != - 1 { line = strings . TrimSpace ( line [ : sharp ] ) } value = line } err = c . flags . Set ( key , value ) if err != nil { log . Println ( " " , key , " " , value , " " , err ) } } return nil }
readConfigFile reads the specified configuration file.
readConfigFile reads the specified configuration file .
// Skip the space and/or equal sign.