fix: update ws client (v1.1.1)

This commit is contained in:
minish 2025-12-29 21:41:26 -05:00
parent 90e1134547
commit 1ea035e9dc
Signed by: min
SSH Key Fingerprint: SHA256:h4k7JNrfe1dzv1WE3oGVeAY9DPSZXIu3/j89+6DtHWE
3 changed files with 16 additions and 9 deletions

View File

@ -5,7 +5,6 @@ import (
"crypto/sha256"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"log"
"time"
@ -26,16 +25,19 @@ type AutoPushClient struct {
unregisterChan chan UnregisterResponse
}
func request[T any](c *AutoPushClient, ch chan T, timeout time.Duration, timeoutErr string, payload any) (res T, err error) {
func request[T any](c *AutoPushClient, ch chan T, timeout time.Duration, errName string, payload any) (res T, err error) {
if err := c.SendJSON(payload); err != nil {
log.Println("websocket request failed", err)
log.Println("websocket send", errName, "request failed", err)
}
select {
case res := <-ch:
case res, ok := <-ch:
if !ok {
return res, fmt.Errorf("websocket recv %s failed (conn close)", errName)
}
return res, err
case <-time.After(timeout * time.Second):
return res, errors.New(timeoutErr)
return res, fmt.Errorf("%s timeout", errName)
}
}

7
go.mod
View File

@ -3,10 +3,13 @@ module git.min.rip/min/webpush-client-go
go 1.23.6
require (
git.min.rip/min/websocket-client-go v1.1.0
git.min.rip/min/websocket-client-go v1.1.1
github.com/google/uuid v1.6.0
golang.org/x/crypto v0.35.0
golang.org/x/net v0.35.0
)
require golang.org/x/text v0.22.0 // indirect
require (
github.com/coder/websocket v1.8.14 // indirect
golang.org/x/text v0.22.0 // indirect
)

6
go.sum
View File

@ -1,5 +1,7 @@
git.min.rip/min/websocket-client-go v1.1.0 h1:DG0IVTE/Wp8BerYX+Vu4q6Up1VGk9zCst5nYPX9sH98=
git.min.rip/min/websocket-client-go v1.1.0/go.mod h1:us3qS+xrO/uPnJjJOuRDuvTAmM+2cEBpiASJhT5fQao=
git.min.rip/min/websocket-client-go v1.1.1 h1:oBIGt2HGPRpeqNY+isDagIKQUQ1W3KhVWJrp0vsMdwA=
git.min.rip/min/websocket-client-go v1.1.1/go.mod h1:qE2autSEJU74jUb+tET0J+Ozg2w7BVtg31Toq83kz4Q=
github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9g=
github.com/coder/websocket v1.8.14/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=