refactor: Use slice.Contains() nettype check

Instead using `||` for each nettype query check , simply using `slice.Contains`.
Also, checking `any` value is not needed here.
This commit is contained in:
Christian Ditaputratama 2024-07-29 22:30:03 +07:00
parent cf77175210
commit 97fad6cacb
No known key found for this signature in database
GPG key ID: 31D3D06D77950979

View file

@ -94,11 +94,9 @@ func (q QueryNodes) toSQL() (args []interface{}, where, sortBy, sortDirection st
wq = append(wq, "(hostname LIKE ? OR ip_addr LIKE ?)")
args = append(args, "%"+q.Host+"%", "%"+q.Host+"%")
}
if q.Nettype != "any" {
if q.Nettype == "mainnet" || q.Nettype == "stagenet" || q.Nettype == "testnet" {
wq = append(wq, "nettype = ?")
args = append(args, q.Nettype)
}
if slices.Contains([]string{"mainnet", "stagenet", "testnet"}, q.Nettype) {
wq = append(wq, "nettype = ?")
args = append(args, q.Nettype)
}
if q.Protocol != "any" && slices.Contains([]string{"tor", "http", "https"}, q.Protocol) {
if q.Protocol == "tor" {