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 { |
| 58 | // её выпердыши |
58 | // её выпердыши |
| 59 | type Media struct { |
59 | type Media struct { |
| 60 | BaseUri string |
60 | BaseUri string |
| 61 | Name string `json:"prettyName"` |
61 | Name string `json:"prettyName"` |
| 62 | Token []string |
62 | Token []string |
| 63 | Types []struct { |
63 | Types []struct { |
| 64 | T string |
64 | T string |
| @@ -109,7 +109,7 @@ func UrlFromMedia(m Media, thumb ...int) (urlParsed, wellFormattedFilename strin |
| 109 | if len(thumb) != 0 { |
109 | if len(thumb) != 0 { |
| 110 | subtractWidthHeight(thumb[0], &t.W, &t.H) |
110 | subtractWidthHeight(thumb[0], &t.W, &t.H) |
| 111 | } |
111 | } |
| 112 | wellFormattedFilename = m.Name + m.BaseUri[l-4:] |
112 | wellFormattedFilename = m.Name + m.BaseUri[l-4:] |
| 113 | |
113 | |
| 114 | url.WriteString("/v1/fit/w_") |
114 | url.WriteString("/v1/fit/w_") |
| 115 | url.WriteString(strconv.Itoa(t.W)) |
115 | url.WriteString(strconv.Itoa(t.W)) |
| @@ -126,7 +126,7 @@ func UrlFromMedia(m Media, thumb ...int) (urlParsed, wellFormattedFilename strin |
| 126 | } |
126 | } |
| 127 | } |
127 | } |
| 128 | |
128 | |
| 129 | urlParsed = url.String() |
129 | urlParsed = url.String() |
| 130 | |
130 | |
| 131 | return |
131 | return |
| 132 | } |
132 | } |
| @@ -149,14 +149,14 @@ func GetDeviation(id string, user string) (st Post, err Error) { |
| 149 | } |
149 | } |
| 150 | } |
150 | } |
| 151 | |
151 | |
| 152 | if err := json.Unmarshal([]byte(txt), &description); err != nil { |
152 | if err := json.Unmarshal([]byte(txt), &description); err != nil { |
| 153 | // Handle error appropriately |
153 | // Handle error appropriately |
| 154 | try(err) // or log/return the error |
154 | try(err) // or log/return the error |
| 155 | } |
155 | } |
| 156 | for _, a := range description.Blocks { |
156 | for _, a := range description.Blocks { |
| 157 | txt = a.Text |
157 | txt = a.Text |
| 158 | } |
158 | } |
| 159 | } |
159 | } |
| 160 | st.Description = txt |
160 | st.Description = txt |
| 161 | |
161 | |
| 162 | return |
162 | return |
misc.go
−5
| @@ -81,11 +81,6 @@ type Search struct { |
| 81 | func PerformSearch(query string, page int, scope rune, user ...string) (ss Search, daError Error, err error) { |
81 | func PerformSearch(query string, page int, scope rune, user ...string) (ss Search, daError Error, err error) { |
| 82 | var buildurl strings.Builder |
82 | var buildurl strings.Builder |
| 83 | |
83 | |
| 84 | if user == nil { |
| |
| 85 | err = errors.New("missing username (last argument)") |
| |
| 86 | return |
| |
| 87 | } |
| |
| 88 | |
| |
| 89 | // о5 построение ссылок. |
84 | // о5 построение ссылок. |
| 90 | switch scope { |
85 | switch scope { |
| 91 | case 'a': // поиск артов по названию |
86 | case 'a': // поиск артов по названию |
user-group.go
+10 −10
| @@ -76,12 +76,12 @@ type Group struct { |
| 76 | |
76 | |
| 77 | // подходит как группа, так и пользователь |
77 | // подходит как группа, так и пользователь |
| 78 | func (s Group) Get() (g GRuser, daError Error, err error) { |
78 | func (s Group) Get() (g GRuser, daError Error, err error) { |
| 79 | if s.Name == "" { |
79 | if s.Name == "" { |
| 80 | return g, daError, errors.New("missing Name field") |
80 | return g, daError, errors.New("missing Name field") |
| 81 | } |
81 | } |
| 82 | daError = ujson("dauserprofile/init/about?username="+s.Name, &g) |
82 | daError = ujson("dauserprofile/init/about?username="+s.Name, &g) |
| 83 | |
83 | |
| 84 | return |
84 | return |
| 85 | } |
85 | } |
| 86 | |
86 | |
| 87 | func (s Group) Favourites(page int, all bool, folderid ...int) (g Group, err Error) { |
87 | 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 |
| 111 | |
111 | |
| 112 | // гарелея пользователя или группы |
112 | // гарелея пользователя или группы |
| 113 | func (s Group) Gallery(page int, folderid ...int) (g Group, daError Error, err error) { |
113 | func (s Group) Gallery(page int, folderid ...int) (g Group, daError Error, err error) { |
| 114 | if s.Name == "" { |
114 | if s.Name == "" { |
| 115 | return g, daError, errors.New("missing Name field") |
115 | return g, daError, errors.New("missing Name field") |
| 116 | } |
116 | } |
| 117 | |
117 | |
| 118 | var url strings.Builder |
118 | var url strings.Builder |
| 119 | if folderid[0] > 0 { |
119 | if folderid[0] > 0 { |
| @@ -135,8 +135,8 @@ func (s Group) Gallery(page int, folderid ...int) (g Group, daError Error, err e |
| 135 | url.WriteString("limit=50") |
135 | url.WriteString("limit=50") |
| 136 | url.WriteString("&with_subfolders=false") |
136 | url.WriteString("&with_subfolders=false") |
| 137 | |
137 | |
| 138 | daError = ujson(url.String(), &g.Content) |
138 | daError = ujson(url.String(), &g.Content) |
| 139 | return |
139 | return |
| 140 | } |
140 | } |
| 141 | |
141 | |
| 142 | type GroupAbout struct { |
142 | type GroupAbout struct { |
util.go
+8 −7
| @@ -27,9 +27,10 @@ func ujson(data string, output any) Error { |
| 27 | |
27 | |
| 28 | type Error struct { |
28 | type Error struct { |
| 29 | Reason string `json:"error"` |
29 | Reason string `json:"error"` |
| 30 | Error string `json:"errorDescription"` |
30 | Error string `json:"errorDescription"` |
| 31 | RAW []byte `json:"-"` |
31 | RAW []byte `json:"-"` |
| 32 | } |
32 | } |
| |
33 | |
| 33 | func APIError(inputError error) (err Error) { |
34 | func APIError(inputError error) (err Error) { |
| 34 | if inputError != nil { |
35 | if inputError != nil { |
| 35 | err.RAW = []byte(inputError.Error()) |
36 | err.RAW = []byte(inputError.Error()) |
| @@ -94,11 +95,11 @@ func request(uri string, other ...string) reqrt { |
| 94 | r.Err = e |
95 | r.Err = e |
| 95 | return r |
96 | return r |
| 96 | } |
97 | } |
| 97 | defer func() { |
98 | defer func() { |
| 98 | if err := resp.Body.Close(); err != nil { |
99 | if err := resp.Body.Close(); err != nil { |
| 99 | try(err) |
100 | try(err) |
| 100 | } |
101 | } |
| 101 | }() |
102 | }() |
| 102 | |
103 | |
| 103 | body, e := io.ReadAll(resp.Body) |
104 | body, e := io.ReadAll(resp.Body) |
| 104 | if e != nil { |
105 | if e != nil { |