MCPcopy
hub / github.com/lifei6671/interview-go / initIPAddress

Function initIPAddress

algorithm/ip-start-end-query.go:43–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41}
42
43func 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
68func ipToInt(ip string) int {
69 ips := strings.Split(ip, ".")

Callers 1

initFunction · 0.85

Calls 1

ipToIntFunction · 0.85

Tested by

no test coverage detected