Skip to content

Commit c06aa97

Browse files
hyangahgopherbot
authored andcommitted
all: run go fix ./...
Change-Id: I66713fa220534c7d26ea2c7793d5e66a905706f4 Reviewed-on: https://go-review.googlesource.com/c/playground/+/802182 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Hyang-Ah Hana Kim <hyangah@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
1 parent fe53175 commit c06aa97

10 files changed

Lines changed: 30 additions & 36 deletions

File tree

cache.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
// responseCache is a common interface for cache implementations.
1515
type responseCache interface {
1616
// Set sets the value for a key.
17-
Set(key string, v interface{}) error
17+
Set(key string, v any) error
1818
// Get sets v to the value stored for a key.
19-
Get(key string, v interface{}) error
19+
Get(key string, v any) error
2020
}
2121

2222
// gobCache stores and retrieves values using a memcache client using the gob
@@ -30,7 +30,7 @@ func newGobCache(addr string) *gobCache {
3030
return &gobCache{memcache.New(addr)}
3131
}
3232

33-
func (c *gobCache) Set(key string, v interface{}) error {
33+
func (c *gobCache) Set(key string, v any) error {
3434
if c == nil {
3535
return nil
3636
}
@@ -41,7 +41,7 @@ func (c *gobCache) Set(key string, v interface{}) error {
4141
return c.client.Set(&memcache.Item{Key: key, Value: buf.Bytes()})
4242
}
4343

44-
func (c *gobCache) Get(key string, v interface{}) error {
44+
func (c *gobCache) Get(key string, v any) error {
4545
if c == nil {
4646
return memcache.ErrCacheMiss
4747
}

examples.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ func newExamplesHandler(gotip bool, modtime time.Time) (*examplesHandler, error)
6666
// Read examples ending in .txt, skipping those ending in .gotip.txt if
6767
// gotip is not set.
6868
prefix := "" // if non-empty, this is a relevant example file
69-
if strings.HasSuffix(name, ".gotip.txt") {
69+
if p, ok := strings.CutSuffix(name, ".gotip.txt"); ok {
7070
if gotip {
71-
prefix = strings.TrimSuffix(name, ".gotip.txt")
71+
prefix = p
7272
}
73-
} else if strings.HasSuffix(name, ".txt") {
74-
prefix = strings.TrimSuffix(name, ".txt")
73+
} else if p, ok := strings.CutSuffix(name, ".txt"); ok {
74+
prefix = p
7575
}
7676

7777
if prefix == "" {

internal/internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func TestPeriodicallyDo(t *testing.T) {
1414
ctx, cancel := context.WithCancel(context.Background())
1515
didWork := make(chan time.Time, 2)
16-
done := make(chan interface{})
16+
done := make(chan any)
1717
go func() {
1818
PeriodicallyDo(ctx, 100*time.Millisecond, func(ctx context.Context, t time.Time) {
1919
select {

logger.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
)
1111

1212
type logger interface {
13-
Printf(format string, args ...interface{})
14-
Errorf(format string, args ...interface{})
15-
Fatalf(format string, args ...interface{})
13+
Printf(format string, args ...any)
14+
Errorf(format string, args ...any)
15+
Fatalf(format string, args ...any)
1616
}
1717

1818
// stdLogger implements the logger interface using the log package.
@@ -30,14 +30,14 @@ func newStdLogger() *stdLogger {
3030
}
3131
}
3232

33-
func (l *stdLogger) Printf(format string, args ...interface{}) {
33+
func (l *stdLogger) Printf(format string, args ...any) {
3434
l.stdout.Printf(format, args...)
3535
}
3636

37-
func (l *stdLogger) Errorf(format string, args ...interface{}) {
37+
func (l *stdLogger) Errorf(format string, args ...any) {
3838
l.stderr.Printf(format, args...)
3939
}
4040

41-
func (l *stdLogger) Fatalf(format string, args ...interface{}) {
41+
func (l *stdLogger) Fatalf(format string, args ...any) {
4242
l.stderr.Fatalf(format, args...)
4343
}

play.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,7 @@ func (r *Recorder) Events() ([]Event, error) {
8585
)
8686

8787
for _, e := range events {
88-
delay := e.time.Sub(now)
89-
if delay < 0 {
90-
delay = 0
91-
}
88+
delay := max(e.time.Sub(now), 0)
9289
out = append(out, Event{
9390
Message: string(sanitize(e.msg)),
9491
Kind: e.kind,
@@ -165,10 +162,7 @@ func decode(kind string, output []byte) ([]event, error) {
165162

166163
// Slurp output.
167164
// Truncated output is OK (probably caused by sandbox limits).
168-
end := i + n
169-
if end > len(output) {
170-
end = len(output)
171-
}
165+
end := min(i+n, len(output))
172166
add(t, output[i:end])
173167
i += n
174168
}

sandbox/sandbox.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ func runHandler(w http.ResponseWriter, r *http.Request) {
545545
t0 := time.Now()
546546
tlast := t0
547547
var logmu sync.Mutex
548-
logf := func(format string, args ...interface{}) {
548+
logf := func(format string, args ...any) {
549549
if !*dev {
550550
return
551551
}
@@ -746,9 +746,9 @@ func sendResponse(w http.ResponseWriter, r *sandboxtypes.Response) {
746746
// cleanStderr removes spam stderr lines from the beginning of x
747747
// and returns a slice of x.
748748
func cleanStderr(x []byte) []byte {
749-
i := bytes.Index(x, containedStderrHeader)
750-
if i == -1 {
749+
_, stderr, ok := bytes.Cut(x, containedStderrHeader)
750+
if !ok {
751751
return x
752752
}
753-
return x[i+len(containedStderrHeader):]
753+
return stderr
754754
}

sandbox_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func TestIsTest(t *testing.T) {
5151
t.Logf("%s:\n%s", strings.Join(cmd.Args, " "), out)
5252

5353
isTestFunction := map[string]bool{}
54-
lines := strings.Split(string(out), "\n")
55-
for _, line := range lines {
54+
lines := strings.SplitSeq(string(out), "\n")
55+
for line := range lines {
5656
// We want Test/Benchmark/Example/Fuzz functions.
5757
// Reject extraneous output such as "ok ...".
5858
if line == "" || !strings.Contains("TBEF", line[:1]) {

server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
9797

9898
// writeJSONResponse JSON-encodes resp and writes to w with the given HTTP
9999
// status.
100-
func (s *server) writeJSONResponse(w http.ResponseWriter, resp interface{}, status int) {
100+
func (s *server) writeJSONResponse(w http.ResponseWriter, resp any, status int) {
101101
w.Header().Set("Content-Type", "application/json")
102102
var buf bytes.Buffer
103103
if err := json.NewEncoder(&buf).Encode(resp); err != nil {

server_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ type testLogger struct {
2626
t *testing.T
2727
}
2828

29-
func (l testLogger) Printf(format string, args ...interface{}) {
29+
func (l testLogger) Printf(format string, args ...any) {
3030
l.t.Logf(format, args...)
3131
}
32-
func (l testLogger) Errorf(format string, args ...interface{}) {
32+
func (l testLogger) Errorf(format string, args ...any) {
3333
l.t.Errorf(format, args...)
3434
}
35-
func (l testLogger) Fatalf(format string, args ...interface{}) {
35+
func (l testLogger) Fatalf(format string, args ...any) {
3636
l.t.Fatalf(format, args...)
3737
}
3838

@@ -361,7 +361,7 @@ type inMemCache struct {
361361

362362
// Set implements the responseCache interface.
363363
// Set stores a *response in the cache. It panics for other types to ensure test failure.
364-
func (i *inMemCache) Set(key string, v interface{}) error {
364+
func (i *inMemCache) Set(key string, v any) error {
365365
i.l.Lock()
366366
defer i.l.Unlock()
367367
if i.m == nil {
@@ -374,7 +374,7 @@ func (i *inMemCache) Set(key string, v interface{}) error {
374374
// Get implements the responseCache interface.
375375
// Get fetches a *response from the cache, or returns a memcache.ErrCacheMiss.
376376
// It panics for other types to ensure test failure.
377-
func (i *inMemCache) Get(key string, v interface{}) error {
377+
func (i *inMemCache) Get(key string, v any) error {
378378
i.l.Lock()
379379
defer i.l.Unlock()
380380
target := v.(*response)

tests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func main() {
226226
return nil
227227
}
228228
have := map[string]bool{}
229-
for _, f := range strings.Split(got, "\n") {
229+
for f := range strings.SplitSeq(got, "\n") {
230230
have[f] = true
231231
}
232232
for _, expect := range []string{

0 commit comments

Comments
 (0)