Commit b97e7e1281

b97e7e1281bc33b873532938495aa02ed5cbb418

parent: b9ef09f5e2

Verified · cmc

cmc <hello@cleberg.net> · 2026-07-15 01:06 UTC

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.

Layout: unified · split

deviantion.go +11 −11
@@ -58,7 +58,7 @@ type Deviation struct {
5858// её выпердыши
5959type Media struct {
6060 BaseUri string
61 Name string `json:"prettyName"`
61 Name string `json:"prettyName"`
6262 Token []string
6363 Types []struct {
6464 T string
@@ -109,7 +109,7 @@ func UrlFromMedia(m Media, thumb ...int) (urlParsed, wellFormattedFilename strin
109109 if len(thumb) != 0 {
110110 subtractWidthHeight(thumb[0], &t.W, &t.H)
111111 }
112 wellFormattedFilename = m.Name + m.BaseUri[l-4:]
112 wellFormattedFilename = m.Name + m.BaseUri[l-4:]
113113
114114 url.WriteString("/v1/fit/w_")
115115 url.WriteString(strconv.Itoa(t.W))
@@ -126,7 +126,7 @@ func UrlFromMedia(m Media, thumb ...int) (urlParsed, wellFormattedFilename strin
126126 }
127127 }
128128
129 urlParsed = url.String()
129 urlParsed = url.String()
130130
131131 return
132132}
@@ -149,14 +149,14 @@ func GetDeviation(id string, user string) (st Post, err Error) {
149149 }
150150 }
151151
152 if err := json.Unmarshal([]byte(txt), &description); err != nil {
153 // Handle error appropriately
154 try(err) // or log/return the error
155 }
156 for _, a := range description.Blocks {
157 txt = a.Text
158 }
159 }
152 if err := json.Unmarshal([]byte(txt), &description); err != nil {
153 // Handle error appropriately
154 try(err) // or log/return the error
155 }
156 for _, a := range description.Blocks {
157 txt = a.Text
158 }
159 }
160160 st.Description = txt
161161
162162 return
misc.go −5
@@ -81,11 +81,6 @@ type Search struct {
8181func PerformSearch(query string, page int, scope rune, user ...string) (ss Search, daError Error, err error) {
8282 var buildurl strings.Builder
8383
84 if user == nil {
85 err = errors.New("missing username (last argument)")
86 return
87 }
88
8984 // о5 построение ссылок.
9085 switch scope {
9186 case 'a': // поиск артов по названию
user-group.go +10 −10
@@ -76,12 +76,12 @@ type Group struct {
7676
7777// подходит как группа, так и пользователь
7878func (s Group) Get() (g GRuser, daError Error, err error) {
79 if s.Name == "" {
80 return g, daError, errors.New("missing Name field")
81 }
82 daError = ujson("dauserprofile/init/about?username="+s.Name, &g)
79 if s.Name == "" {
80 return g, daError, errors.New("missing Name field")
81 }
82 daError = ujson("dauserprofile/init/about?username="+s.Name, &g)
8383
84 return
84 return
8585}
8686
8787func (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
111111
112112// гарелея пользователя или группы
113113func (s Group) Gallery(page int, folderid ...int) (g Group, daError Error, err error) {
114 if s.Name == "" {
115 return g, daError, errors.New("missing Name field")
116 }
114 if s.Name == "" {
115 return g, daError, errors.New("missing Name field")
116 }
117117
118118 var url strings.Builder
119119 if folderid[0] > 0 {
@@ -135,8 +135,8 @@ func (s Group) Gallery(page int, folderid ...int) (g Group, daError Error, err e
135135 url.WriteString("limit=50")
136136 url.WriteString("&with_subfolders=false")
137137
138 daError = ujson(url.String(), &g.Content)
139 return
138 daError = ujson(url.String(), &g.Content)
139 return
140140}
141141
142142type GroupAbout struct {
util.go +8 −7
@@ -27,9 +27,10 @@ func ujson(data string, output any) Error {
2727
2828type Error struct {
2929 Reason string `json:"error"`
30 Error string `json:"errorDescription"`
31 RAW []byte `json:"-"`
30 Error string `json:"errorDescription"`
31 RAW []byte `json:"-"`
3232}
33
3334func APIError(inputError error) (err Error) {
3435 if inputError != nil {
3536 err.RAW = []byte(inputError.Error())
@@ -94,11 +95,11 @@ func request(uri string, other ...string) reqrt {
9495 r.Err = e
9596 return r
9697 }
97 defer func() {
98 if err := resp.Body.Close(); err != nil {
99 try(err)
100 }
101 }()
98 defer func() {
99 if err := resp.Body.Close(); err != nil {
100 try(err)
101 }
102 }()
102103
103104 body, e := io.ReadAll(resp.Body)
104105 if e != nil {