summaryrefslogtreecommitdiff
path: root/internal/api/util/parsequery.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-07-31 15:47:35 +0200
committerLibravatar GitHub <noreply@github.com>2023-07-31 15:47:35 +0200
commit2796a2e82f16ade9872008878cf88299bd66b4e7 (patch)
tree76f7b69cc1da57ca10b71c57abf1892575bea100 /internal/api/util/parsequery.go
parent[performance] cache follow, follow request and block ID lists (#2027) (diff)
downloadgotosocial-2796a2e82f16ade9872008878cf88299bd66b4e7.tar.xz
[feature] Hashtag federation (in/out), hashtag client API endpoints (#2032)
* update go-fed * do the things * remove unused columns from tags * update to latest lingo from main * further tag shenanigans * serve stub page at tag endpoint * we did it lads * tests, oh tests, ohhh tests, oh tests (doo doo doo doo) * swagger docs * document hashtag usage + federation * instanceGet * don't bother parsing tag href * rename whereStartsWith -> whereStartsLike * remove GetOrCreateTag * dont cache status tag timelineability
Diffstat (limited to 'internal/api/util/parsequery.go')
-rw-r--r--internal/api/util/parsequery.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/api/util/parsequery.go b/internal/api/util/parsequery.go
index 662870910..a87c77aeb 100644
--- a/internal/api/util/parsequery.go
+++ b/internal/api/util/parsequery.go
@@ -20,11 +20,18 @@ package util
import (
"fmt"
"strconv"
+ "strings"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
)
const (
+ /* API version keys */
+
+ APIVersionKey = "api_version"
+ APIv1 = "v1"
+ APIv2 = "v2"
+
/* Common keys */
IDKey = "id"
@@ -44,6 +51,10 @@ const (
SearchResolveKey = "resolve"
SearchTypeKey = "type"
+ /* Tag keys */
+
+ TagNameKey = "tag_name"
+
/* Web endpoint keys */
WebUsernameKey = "username"
@@ -122,6 +133,26 @@ func ParseDomainBlockImport(value string, defaultValue bool) (bool, gtserror.Wit
Parse functions for *REQUIRED* parameters.
*/
+func ParseAPIVersion(value string, availableVersion ...string) (string, gtserror.WithCode) {
+ key := APIVersionKey
+
+ if value == "" {
+ return "", requiredError(key)
+ }
+
+ for _, av := range availableVersion {
+ if value == av {
+ return value, nil
+ }
+ }
+
+ err := fmt.Errorf(
+ "invalid API version, valid versions for this path are [%s]",
+ strings.Join(availableVersion, ", "),
+ )
+ return "", gtserror.NewErrorBadRequest(err, err.Error())
+}
+
func ParseID(value string) (string, gtserror.WithCode) {
key := IDKey
@@ -152,6 +183,16 @@ func ParseSearchQuery(value string) (string, gtserror.WithCode) {
return value, nil
}
+func ParseTagName(value string) (string, gtserror.WithCode) {
+ key := TagNameKey
+
+ if value == "" {
+ return "", requiredError(key)
+ }
+
+ return value, nil
+}
+
func ParseWebUsername(value string) (string, gtserror.WithCode) {
key := WebUsernameKey