krz/devianter

A DeviantArt guest API library for Go.

clone: git clone https://gitbay.org/krz/devianter.git

b97e7e1281bc33b873532938495aa02ed5cbb418

verified · cmc

author: Christian Cleberg <hello@cleberg.net> · 2026-07-15T01:06:44Z

fix: restore optional username in PerformSearch, apply gofmt

The golangci-lint cleanup added a top-level `user == nil` guard to
PerformSearch, but `user` is variadic and only required for the 'g' and
'f' scopes. The guard made every 'a'/'t' search fail with "missing
username" before issuing a request, breaking general search for all
callers. The correctly scoped check inside the 'g','f' case already
covers the case that needs it.

Also run gofmt: the same cleanup introduced space indentation in
deviantion.go, user-group.go, and util.go, which fails the gofmt CI step.
 deviantion.go | 22 +++++++++++-----------
 misc.go       |  5 -----
 user-group.go | 20 ++++++++++----------
 util.go       | 15 ++++++++-------
 4 files changed, 29 insertions(+), 33 deletions(-)

diff --git a/deviantion.go b/deviantion.go
index 197f2af..12c7a14 100644
--- a/deviantion.go
+++ b/deviantion.go
@@ -58,7 +58,7 @@ type Deviation struct {
 // её выпердыши
 type Media struct {
 	BaseUri string
-  Name string `json:"prettyName"`
+	Name    string `json:"prettyName"`
 	Token   []string
 	Types   []struct {
 		T    string
@@ -109,7 +109,7 @@ func UrlFromMedia(m Media, thumb ...int) (urlParsed, wellFormattedFilename strin
 				if len(thumb) != 0 {
 					subtractWidthHeight(thumb[0], &t.W, &t.H)
 				}
-        wellFormattedFilename = m.Name + m.BaseUri[l-4:]
+				wellFormattedFilename = m.Name + m.BaseUri[l-4:]
 
 				url.WriteString("/v1/fit/w_")
 				url.WriteString(strconv.Itoa(t.W))
@@ -126,7 +126,7 @@ func UrlFromMedia(m Media, thumb ...int) (urlParsed, wellFormattedFilename strin
 		}
 	}
 
-  urlParsed = url.String()
+	urlParsed = url.String()
 
 	return
 }
@@ -149,14 +149,14 @@ func GetDeviation(id string, user string) (st Post, err Error) {
 			}
 		}
 
-        if err := json.Unmarshal([]byte(txt), &description); err != nil {
-            // Handle error appropriately
-            try(err) // or log/return the error
-        }
-        for _, a := range description.Blocks {
-            txt = a.Text
-        }
-    }
+		if err := json.Unmarshal([]byte(txt), &description); err != nil {
+			// Handle error appropriately
+			try(err) // or log/return the error
+		}
+		for _, a := range description.Blocks {
+			txt = a.Text
+		}
+	}
 	st.Description = txt
 
 	return
diff --git a/misc.go b/misc.go
index 8e6c5aa..6b34050 100644
--- a/misc.go
+++ b/misc.go
@@ -81,11 +81,6 @@ type Search struct {
 func PerformSearch(query string, page int, scope rune, user ...string) (ss Search, daError Error, err error) {
 	var buildurl strings.Builder
 
-    if user == nil {
-        err = errors.New("missing username (last argument)")
-        return
-    }
-
 	// о5 построение ссылок.
 	switch scope {
 	case 'a': // поиск артов по названию
diff --git a/user-group.go b/user-group.go
index d84c2c8..dba8a91 100644
--- a/user-group.go
+++ b/user-group.go
@@ -76,12 +76,12 @@ type Group struct {
 
 // подходит как группа, так и пользователь
 func (s Group) Get() (g GRuser, daError Error, err error) {
-    if s.Name == "" {
-        return g, daError, errors.New("missing Name field")
-    }
-    daError = ujson("dauserprofile/init/about?username="+s.Name, &g)
+	if s.Name == "" {
+		return g, daError, errors.New("missing Name field")
+	}
+	daError = ujson("dauserprofile/init/about?username="+s.Name, &g)
 
-    return
+	return
 }
 
 func (s Group) Favourites(page int, all bool, folderid ...int) (g Group, err Error) {
@@ -111,9 +111,9 @@ func (s Group) Favourites(page int, all bool, folderid ...int) (g Group, err Err
 
 // гарелея пользователя или группы
 func (s Group) Gallery(page int, folderid ...int) (g Group, daError Error, err error) {
-    if s.Name == "" {
-        return g, daError, errors.New("missing Name field")
-    }
+	if s.Name == "" {
+		return g, daError, errors.New("missing Name field")
+	}
 
 	var url strings.Builder
 	if folderid[0] > 0 {
@@ -135,8 +135,8 @@ func (s Group) Gallery(page int, folderid ...int) (g Group, daError Error, err e
 	url.WriteString("limit=50")
 	url.WriteString("&with_subfolders=false")
 
-    daError = ujson(url.String(), &g.Content)
-    return
+	daError = ujson(url.String(), &g.Content)
+	return
 }
 
 type GroupAbout struct {
diff --git a/util.go b/util.go
index ac3e3e4..1f5c0e3 100644
--- a/util.go
+++ b/util.go
@@ -27,9 +27,10 @@ func ujson(data string, output any) Error {
 
 type Error struct {
 	Reason string `json:"error"`
-	Error string `json:"errorDescription"`
-	RAW []byte `json:"-"`
+	Error  string `json:"errorDescription"`
+	RAW    []byte `json:"-"`
 }
+
 func APIError(inputError error) (err Error) {
 	if inputError != nil {
 		err.RAW = []byte(inputError.Error())
@@ -94,11 +95,11 @@ func request(uri string, other ...string) reqrt {
 		r.Err = e
 		return r
 	}
-    defer func() {
-        if err := resp.Body.Close(); err != nil {
-            try(err)
-        }
-    }()
+	defer func() {
+		if err := resp.Body.Close(); err != nil {
+			try(err)
+		}
+	}()
 
 	body, e := io.ReadAll(resp.Body)
 	if e != nil {