| 29 | } |
| 30 | |
| 31 | func (o dependgraph) ReadFile(path string) error { |
| 32 | file, err := os.Open(path) |
| 33 | |
| 34 | if err != nil { |
| 35 | return err |
| 36 | } |
| 37 | |
| 38 | defer file.Close() |
| 39 | |
| 40 | confirmMode := false |
| 41 | |
| 42 | scanner := bufio.NewScanner(file) |
| 43 | for scanner.Scan() { |
| 44 | splitLine := strings.Split(scanner.Text(), " ") |
| 45 | |
| 46 | if !confirmMode { |
| 47 | if splitLine[1] != "graph" { |
| 48 | return fmt.Errorf("received invalid mode type '%s'", splitLine[2]) |
| 49 | } |
| 50 | |
| 51 | confirmMode = true |
| 52 | continue |
| 53 | } |
| 54 | |
| 55 | if o[splitLine[0]] == nil { |
| 56 | o[splitLine[0]] = make([]string, 0) |
| 57 | } |
| 58 | |
| 59 | o[splitLine[0]] = append(o[splitLine[0]], splitLine[1]) |
| 60 | } |
| 61 | |
| 62 | if err := scanner.Err(); err != nil { |
| 63 | return err |
| 64 | } |
| 65 | |
| 66 | return nil |
| 67 | } |