feat: add shared query param helpers for jikan
This commit is contained in:
43
integrations/jikan/query_params.go
Normal file
43
integrations/jikan/query_params.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package jikan
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func buildRequestURL(baseURL, path string, params url.Values) string {
|
||||
encoded := params.Encode()
|
||||
if encoded == "" {
|
||||
return fmt.Sprintf("%s%s", baseURL, path)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s%s?%s", baseURL, path, encoded)
|
||||
}
|
||||
|
||||
func setQueryValue(values url.Values, key, value string) {
|
||||
if value == "" {
|
||||
values.Del(key)
|
||||
return
|
||||
}
|
||||
|
||||
values.Set(key, value)
|
||||
}
|
||||
|
||||
func setPositiveIntQueryValue(values url.Values, key string, value int) {
|
||||
if value <= 0 {
|
||||
values.Del(key)
|
||||
return
|
||||
}
|
||||
|
||||
values.Set(key, strconv.Itoa(value))
|
||||
}
|
||||
|
||||
func setTrueQueryValue(values url.Values, key string, enabled bool) {
|
||||
if !enabled {
|
||||
values.Del(key)
|
||||
return
|
||||
}
|
||||
|
||||
values.Set(key, "true")
|
||||
}
|
||||
Reference in New Issue
Block a user