ipbl/src/models/utils.go
Paul Lecuq 8d45b04e99
All checks were successful
continuous-integration/drone/push Build is passing
code cleanup
2023-11-03 11:02:06 +01:00

32 lines
545 B
Go

package models
import "reflect"
func Differ(sl1 []IP, sl2 []IP) (toinsert []IP, err error) {
var m = make(map[string]IPDiffer)
longslice := append(sl1, sl2...)
for _, v2 := range longslice {
if _, v := m[v2.IP]; !v {
m[v2.IP] = IPDiffer{IP: v2, Num: 1}
} else {
if this, ok := m[v2.IP]; ok {
this.Num++
m[v2.IP] = this
}
}
}
for _, j := range reflect.ValueOf(m).MapKeys() {
if m[j.String()].Num == 1 {
toinsert = append(toinsert, m[j.String()].IP)
}
}
return
}
type IPDiffer struct {
IP IP
Num int
}