File tree 1 file changed +10
-2
lines changed
1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -20,17 +20,25 @@ import (
20
20
// fmt.Println(next)
21
21
//}
22
22
23
- func FindAvailableIP (cidr string , allocated map [string ]struct {}) (string , error ) {
23
+ func FindAvailableIP (cidr string , allocated []string ) (string , error ) {
24
+ allocatedMap := toMap (allocated )
24
25
ips , _ := cidrIPs (cidr )
25
26
for _ , ip := range ips {
26
27
fmt .Println (ip )
27
- if _ , found := allocated [ip ]; ! found {
28
+ if _ , found := allocatedMap [ip ]; ! found {
28
29
return ip , nil
29
30
}
30
31
}
31
32
return "" , fmt .Errorf ("no available IPs in range %v" , cidr )
32
33
}
33
34
35
+ func toMap (strings []string ) (m map [string ]struct {}) {
36
+ for _ , s := range strings {
37
+ m [s ] = struct {}{}
38
+ }
39
+ return
40
+ }
41
+
34
42
func cidrIPs (cidr string ) ([]string , error ) {
35
43
ip , ipnet , err := net .ParseCIDR (cidr )
36
44
You can’t perform that action at this time.
0 commit comments