Make nettype and protocol query more strict

It will return error if nettype and protocol query string value is wrong
This commit is contained in:
ditatompel 2024-05-09 20:44:49 +07:00
parent ec11fa0126
commit efca11e51c
No known key found for this signature in database
GPG key ID: 31D3D06D77950979

View file

@ -108,10 +108,17 @@ func (repo *MoneroRepo) Nodes(q MoneroQueryParams) (MoneroNodes, error) {
queryParams = append(queryParams, "%"+q.Host+"%")
}
if q.NetType != "any" {
if q.NetType != "mainnet" && q.NetType != "stagenet" && q.NetType != "testnet" {
return MoneroNodes{}, errors.New("Invalid nettype, must be one of 'mainnet', 'stagenet', 'testnet' or 'any'")
}
whereQueries = append(whereQueries, "nettype = ?")
queryParams = append(queryParams, q.NetType)
}
if q.Protocol != "any" {
allowedProtocols := []string{"tor", "http", "https"}
if !slices.Contains(allowedProtocols, q.Protocol) {
return MoneroNodes{}, errors.New("Invalid protocol, must be one of '" + strings.Join(allowedProtocols, "', '") + "' or 'any'")
}
if q.Protocol == "tor" {
whereQueries = append(whereQueries, "is_tor = ?")
queryParams = append(queryParams, 1)