From 97fad6cacb9c9e801229a46f155b0c048cd254bf Mon Sep 17 00:00:00 2001 From: Christian Ditaputratama Date: Mon, 29 Jul 2024 22:30:03 +0700 Subject: [PATCH] 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. --- internal/monero/monero.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/monero/monero.go b/internal/monero/monero.go index 14ce586..1686af0 100644 --- a/internal/monero/monero.go +++ b/internal/monero/monero.go @@ -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" {