We can decrease validation time for some validators with `go`
Standard [[ https://github.com/vyos/vyos-1x/blob/current/src/validators/ipv4-range | validator ]] `ipv4-range`
```
vyos@r14# time sudo sh -c ' for ((n=0;n<10000;n++)); do /usr/libexec/vyos/validate-value --exec /usr/libexec/vyos/validators/ipv4-range --value "192.0.2.1-192.0.2.100"; done'
real 0m48.825s
user 0m26.534s
sys 0m23.904s
[edit]
vyos@r14#
```
The same validator in PoC `go`
```
vyos@r14# time sudo sh -c ' for ((n=0;n<10000;n++)); do /usr/libexec/vyos/validate-value --exec /usr/libexec/vyos/validators/ipv4-range-go --value "192.0.2.1-192.0.2.100"; done'
real 0m27.069s
user 0m12.814s
sys 0m14.784s
[edit]
vyos@r14#
```
There is an example of code:
```
$ cat ipv4-range.go
package main
import (
"net"
"os"
"strings"
"math/big"
)
var (
hosts = os.Args[1]
)
func IP4toInt(IPv4Address net.IP) int64 {
IPv4Int := big.NewInt(0)
IPv4Int.SetBytes(IPv4Address.To4())
return IPv4Int.Int64()
}
func IsIPv4(ip string) bool {
if net.ParseIP(ip) == nil {
return false
}
return true
}
func main() {
dash := strings.Contains(hosts, "-")
if dash == false {
os.Exit(1)
}
lines := strings.Split(hosts, "-")
first, second := string(lines[0]), string(lines[1])
dec_first := IP4toInt(net.ParseIP(first))
dec_second := IP4toInt(net.ParseIP(second))
if dec_first >= dec_second {
os.Exit(1)
}
for _, host := range lines {
if IsIPv4(host) == false {
os.Exit(1)
}
}
}
```