func load(filename string) (*Filter, error) { lines, err := fsutil.LoadLines(filename) if err != nil { return nil, err } return New(lines) }
func loadComputedFiles(filename string) ([]computedFileType, error) { var computedFileList []computedFileType if strings.HasSuffix(filename, ".json") { file, err := os.Open(filename) if err != nil { return nil, err } defer file.Close() reader := bufio.NewReader(file) decoder := json.NewDecoder(reader) if err := decoder.Decode(&computedFileList); err != nil { return nil, errors.New("error decoding computed files list " + err.Error()) } } else { lines, err := fsutil.LoadLines(filename) if err != nil { return nil, err } for _, line := range lines { fields := strings.Fields(line) if len(fields) != 2 { return nil, fmt.Errorf("bad line: %s", line) } computedFileList = append(computedFileList, computedFileType{fields[0], fields[1]}) } } return computedFileList, nil }
func loadConfiguration(manager *filegen.Manager, filename string) error { lines, err := fsutil.LoadLines(filename) if err != nil { return fmt.Errorf("error loading configuration file: %s", err) } for _, line := range lines { fields := strings.Fields(line) if len(fields) < 2 { return fmt.Errorf("insufficient fields in line: \"%s\"", line) } config, ok := configs[fields[0]] if !ok { return fmt.Errorf("unknown generator type: %s", fields[0]) } numParams := len(fields) - 2 if numParams < config.minParams { return fmt.Errorf("insufficient params in line: \"%s\"", line) } if config.maxParams >= 0 && numParams > config.maxParams { return fmt.Errorf("too many params in line: \"%s\"", line) } if err := config.configFunc(manager, fields[1], fields[2:]); err != nil { return err } } return nil }