()
| 41 | } |
| 42 | |
| 43 | func initIPAddress() error { |
| 44 | f, err := os.Open("./testdata/ip.data") |
| 45 | if err != nil { |
| 46 | return err |
| 47 | } |
| 48 | defer f.Close() |
| 49 | |
| 50 | scanner := bufio.NewScanner(f) |
| 51 | for scanner.Scan() { |
| 52 | line := scanner.Text() |
| 53 | |
| 54 | item := strings.Split(line, " ") |
| 55 | |
| 56 | start := item[0] |
| 57 | ipint := ipToInt(start) |
| 58 | ipMap[ipint] = IPAddr{ |
| 59 | start: start, |
| 60 | end: item[1], |
| 61 | addr: item[2], |
| 62 | } |
| 63 | ipIndex = append(ipIndex, ipint) |
| 64 | } |
| 65 | return nil |
| 66 | } |
| 67 | |
| 68 | func ipToInt(ip string) int { |
| 69 | ips := strings.Split(ip, ".") |