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 | 59 | type Media struct { |
| 60 | 60 | BaseUri string |
| 61 | | Name string `json:"prettyName"` |
| 61 | Name string `json:"prettyName"` |
| 62 | 62 | Token []string |
| 63 | 63 | Types []struct { |
| 64 | 64 | T string |
| @@ -109,7 +109,7 @@ func UrlFromMedia(m Media, thumb ...int) (urlParsed, wellFormattedFilename strin |
| 109 | 109 | if len(thumb) != 0 { |
| 110 | 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 | 114 | url.WriteString("/v1/fit/w_") |
| 115 | 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 | 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 { |
| 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 | } |
| 160 | 160 | st.Description = txt |
| 161 | 161 | |
| 162 | 162 | return |
misc.go
−5
| @@ -81,11 +81,6 @@ type Search struct { |
| 81 | 81 | func PerformSearch(query string, page int, scope rune, user ...string) (ss Search, daError Error, err error) { |
| 82 | 82 | var buildurl strings.Builder |
| 83 | 83 | |
| 84 | | if user == nil { |
| 85 | | err = errors.New("missing username (last argument)") |
| 86 | | return |
| 87 | | } |
| 88 | | |
| 89 | 84 | // о5 построение ссылок. |
| 90 | 85 | switch scope { |
| 91 | 86 | case 'a': // поиск артов по названию |
user-group.go
+10 −10
| @@ -76,12 +76,12 @@ type Group struct { |
| 76 | 76 | |
| 77 | 77 | // подходит как группа, так и пользователь |
| 78 | 78 | func (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) |
| 83 | 83 | |
| 84 | | return |
| 84 | return |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 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 | 113 | func (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 | } |
| 117 | 117 | |
| 118 | 118 | var url strings.Builder |
| 119 | 119 | if folderid[0] > 0 { |
| @@ -135,8 +135,8 @@ func (s Group) Gallery(page int, folderid ...int) (g Group, daError Error, err e |
| 135 | 135 | url.WriteString("limit=50") |
| 136 | 136 | url.WriteString("&with_subfolders=false") |
| 137 | 137 | |
| 138 | | daError = ujson(url.String(), &g.Content) |
| 139 | | return |
| 138 | daError = ujson(url.String(), &g.Content) |
| 139 | return |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | type GroupAbout struct { |
util.go
+8 −7
| @@ -27,9 +27,10 @@ func ujson(data string, output any) Error { |
| 27 | 27 | |
| 28 | 28 | type Error struct { |
| 29 | 29 | Reason string `json:"error"` |
| 30 | | Error string `json:"errorDescription"` |
| 31 | | RAW []byte `json:"-"` |
| 30 | Error string `json:"errorDescription"` |
| 31 | RAW []byte `json:"-"` |
| 32 | 32 | } |
| 33 | |
| 33 | 34 | func APIError(inputError error) (err Error) { |
| 34 | 35 | if inputError != nil { |
| 35 | 36 | err.RAW = []byte(inputError.Error()) |
| @@ -94,11 +95,11 @@ func request(uri string, other ...string) reqrt { |
| 94 | 95 | r.Err = e |
| 95 | 96 | return r |
| 96 | 97 | } |
| 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 | }() |
| 102 | 103 | |
| 103 | 104 | body, e := io.ReadAll(resp.Body) |
| 104 | 105 | if e != nil { |