Skip to content

Commit 128e075

Browse files
authored
all: run modernize (#43)
1 parent f46c2e7 commit 128e075

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

web/internal/hashfs/hashfs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func TestFileServer(t *testing.T) {
184184
h := hashfs.FileServer(fsys)
185185
hash := "\"b633a587c652d02386c4f16f8c6f6aab7352d97f16367c3c40576214372dd628\""
186186

187-
for i := 0; i < 2; i++ {
187+
for range 2 {
188188
w := httptest.NewRecorder()
189189
h.ServeHTTP(w, r)
190190

web/respond.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ func respondJSON(w http.ResponseWriter, response any, wroteStatus bool) {
8181
if !wroteStatus {
8282
w.WriteHeader(http.StatusInternalServerError)
8383
}
84-
w.Write([]byte(fmt.Sprintf(`{
84+
w.Write(fmt.Appendf(nil, `{
8585
"status": "error",
8686
"error": "JSON marshal error: %s"
87-
}`, escapeForJSON(err.Error()))))
87+
}`, escapeForJSON(err.Error())))
8888
return
8989
}
9090
w.Write(b)
@@ -150,7 +150,7 @@ func respondError(json bool, w http.ResponseWriter, r *http.Request, err error)
150150
}
151151
w.WriteHeader(int(se))
152152
if se == ErrInternalServerError {
153-
logf("Error %d (%s): %v", se, http.StatusText(int(se)), err)
153+
logf("%s: %s %s -> %v", http.StatusText(int(se)), r.Method, r.URL.Path, err)
154154
}
155155
if json {
156156
respondJSON(w, &errorResponse{Status: "error", Error: err.Error()}, true)
@@ -173,7 +173,7 @@ func respondError(json bool, w http.ResponseWriter, r *http.Request, err error)
173173

174174
var buf bytes.Buffer
175175
if err := errorTemplate.Execute(&buf, data); err != nil {
176-
logf("Executing error template failed: %v", err)
176+
logf("web.RespondError: executing error template failed: %v", err)
177177
// Fallback, if template execution fails.
178178
fmt.Fprintf(w, "%d: %s", data.StatusCode, data.StatusText)
179179
return

web/server_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,11 @@ func TestServerListenAndServe(t *testing.T) {
8282
Ready: readyFunc,
8383
}
8484

85-
wg.Add(1)
86-
go func() {
87-
defer wg.Done()
85+
wg.Go(func() {
8886
if err := s.ListenAndServe(cli.WithEnv(ctx, env)); err != nil {
8987
errCh <- err
9088
}
91-
}()
89+
})
9290

9391
// Wait until the server is ready.
9492
select {

web/tgauth/tgauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func delCookie(w http.ResponseWriter, key string) {
203203

204204
func authDataToIdentity(data string) (*Identity, error) {
205205
dataMap := make(map[string]string)
206-
for _, line := range strings.Split(data, "\n") {
206+
for line := range strings.SplitSeq(data, "\n") {
207207
parts := strings.SplitN(line, "=", 2)
208208
if len(parts) == 2 {
209209
dataMap[parts[0]] = parts[1]

0 commit comments

Comments
 (0)