Skip to content

Commit 15adeee

Browse files
committed
Look for other opportunities to use Go 1.25
The easy one is sync.WaitGroup.Go. At least for the cases where I'm not doing weird and special things with WaitGroups. Despite all I've done with the pre-release versions, I had no idea net/http was getting built-in CSRF protection until today. It's not perfect since it relies on a relatively new browser feature, but it's certainly better than the "don't use this" comment I have in the RPC handler package right now. I'd like to take my time working it in, though.
1 parent dfdc7a8 commit 15adeee

File tree

4 files changed

+4
-12
lines changed

4 files changed

+4
-12
lines changed

internal/api/rpc/rpc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// This framework is not considered acceptable for Internet-facing production
1414
// use. For example, the Content-Type enforcement described above is the only
1515
// mitigation against cross-site request forgery attacks.
16+
// (TODO: Consider adopting http.CrossOriginProtection from Go 1.25.)
1617
package rpc
1718

1819
import (

internal/api/tunerstatus.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ func (tsh *TunerStatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
4848
}
4949
defer tsh.socket.Close()
5050

51-
tsh.waitGroup.Add(1)
52-
go func() {
53-
defer tsh.waitGroup.Done()
54-
tsh.drainClient()
55-
}()
51+
tsh.waitGroup.Go(tsh.drainClient)
5652

5753
tsh.watch = tsh.tuner.WatchStatus(tsh.sendNewTunerStatus)
5854
defer tsh.watch.Cancel()

internal/api/webrtc.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ func (wh *WebRTCHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
8686
}
8787
defer wh.rtcPeer.Close()
8888

89-
wh.waitGroup.Add(1)
90-
go func() {
91-
defer wh.waitGroup.Done()
92-
wh.handleClientSessionAnswers()
93-
}()
89+
wh.waitGroup.Go(wh.handleClientSessionAnswers)
9490

9591
wh.watch = wh.tuner.WatchTracks(wh.handleTrackUpdate)
9692
defer wh.watch.Cancel()

internal/watch/watch_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ func TestValueStress(t *testing.T) {
4848
}
4949

5050
var setGroup sync.WaitGroup
51-
setGroup.Add(nWrites - 1)
5251
for i := 1; i <= nWrites-1; i++ {
5352
// This will quickly make the race detector complain if Set is not properly
5453
// synchronized.
55-
go func() { defer setGroup.Done(); v.Set(i) }()
54+
setGroup.Go(func() { v.Set(i) })
5655
}
5756
setGroup.Wait()
5857

0 commit comments

Comments
 (0)