Skip to content

Commit e1ae66f

Browse files
Modernize (#9)
1 parent fa03bb1 commit e1ae66f

File tree

8 files changed

+12
-17
lines changed

8 files changed

+12
-17
lines changed

notifier/redis.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (db *DB) FinishDB() {
211211

212212
// The first half of the transaction. WATCH the key and fetch its value.
213213
// On error, UNWATCH the key.
214-
func (db *DB) watchAndGet(key string) (interface{}, error) {
214+
func (db *DB) watchAndGet(key string) (any, error) {
215215
c, err := db.getPool()
216216
if err != nil {
217217
return nil, wrapErr(500, err)
@@ -246,7 +246,7 @@ func (db *DB) unwatch() {
246246
// WATCHed. Encode payload by json and write it then commit,
247247
// or discard everything if any step fails. On success, returns
248248
// what EXEC returns and nil. On error, returns nil and *appError.
249-
func (db *DB) updateAndCommit(key string, payload interface{}) (interface{}, error) {
249+
func (db *DB) updateAndCommit(key string, payload any) (any, error) {
250250
c, err := db.getPool()
251251
if err != nil {
252252
return nil, wrapErr(500, err)
@@ -294,13 +294,13 @@ func (db *DB) GetChannels(appname string) (map[string]*Channel, error) {
294294
if err != nil {
295295
return nil, wrapErr(500, err)
296296
}
297-
ar, ok := r.([]interface{})
297+
ar, ok := r.([]any)
298298
if !ok {
299299
return nil, appErr(500, fmt.Sprintf("redis SCAN returned weird value: %v", r))
300300
}
301301

302302
next := string(ar[0].([]byte))
303-
keys, ok := ar[1].([]interface{})
303+
keys, ok := ar[1].([]any)
304304
if !ok {
305305
return nil, appErr(500, fmt.Sprintf("redis SCAN returned weird value: %v", r))
306306
}

notifier/redis_init_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build redis_test
2-
// +build redis_test
32

43
package notifier
54

notifier/redis_sentinel_init_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build redis_sentinel_test
2-
// +build redis_sentinel_test
32

43
package notifier
54

notifier/redis_socket_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build chrome_test && redis_test
2-
// +build chrome_test,redis_test
32

43
package notifier
54

notifier/redis_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build redis_test || redis_sentinel_test
2-
// +build redis_test redis_sentinel_test
32

43
package notifier
54

notifier/socket.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type ConnectionEstablishedData struct {
2929
ActivityTimeout int `json:"activity_timeout"`
3030
}
3131

32-
func encodePusherEvent(eventName string, chanName string, data interface{}) ([]byte, error) {
32+
func encodePusherEvent(eventName string, chanName string, data any) ([]byte, error) {
3333
s, ok := data.(string)
3434
if !ok {
3535
js, err := json.Marshal(data)
@@ -62,7 +62,7 @@ func (s *Supervisor) socketFinish(u *User, logmsg string, err error) {
6262
_ = u.Connection.Close()
6363
}
6464

65-
func (s *Supervisor) socketSend(u *User, eventName string, chanName string, data interface{}) {
65+
func (s *Supervisor) socketSend(u *User, eventName string, chanName string, data any) {
6666
msg, err := encodePusherEvent(eventName, chanName, data)
6767
if err != nil {
6868
s.socketFinish(u, "[internal] marshalling send packet error", err)
@@ -74,7 +74,7 @@ func (s *Supervisor) socketSend(u *User, eventName string, chanName string, data
7474
}
7575
}
7676

77-
func (s *Supervisor) socketSendInvalid(u *User, event string, received interface{}) {
77+
func (s *Supervisor) socketSendInvalid(u *User, event string, received any) {
7878
s.logger.Debugw("invalid event",
7979
"event", event,
8080
"data", received)
@@ -115,8 +115,8 @@ func (s *Supervisor) socketMessageHandleLoop(u *User) {
115115
s.logger.Infow("received", "message", string(p))
116116

117117
var ev struct {
118-
Name string `json:"event"`
119-
Data interface{} `json:"data"`
118+
Name string `json:"event"`
119+
Data any `json:"data"`
120120
}
121121
err = json.Unmarshal(p, &ev)
122122
if err != nil {
@@ -128,7 +128,7 @@ func (s *Supervisor) socketMessageHandleLoop(u *User) {
128128
case "pusher:ping":
129129
s.socketSend(u, "pusher:pong", "", "ok")
130130
case "pusher:subscribe":
131-
m, ok := ev.Data.(map[string]interface{})
131+
m, ok := ev.Data.(map[string]any)
132132
if !ok {
133133
s.socketSendInvalid(u, ev.Name, ev.Data)
134134
break
@@ -155,7 +155,7 @@ func (s *Supervisor) socketMessageHandleLoop(u *User) {
155155
}
156156
s.socketSend(u, "pusher_internal:subscription_succeeded", channel.(string), "ok")
157157
case "pusher:unsubscribe":
158-
m, ok := ev.Data.(map[string]interface{})
158+
m, ok := ev.Data.(map[string]any)
159159
if !ok {
160160
s.socketSendInvalid(u, ev.Name, ev.Data)
161161
break

notifier/socket_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build chrome_test
2-
// +build chrome_test
32

43
package notifier
54

notifier/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type getChannelResponse struct {
5353
SubscriptionCount int `json:"subscription_count,omitempty"`
5454
}
5555

56-
func returnJSON(w http.ResponseWriter, val interface{}) {
56+
func returnJSON(w http.ResponseWriter, val any) {
5757
js, err := json.Marshal(val)
5858
if err != nil {
5959
http.Error(w, err.Error(), http.StatusInternalServerError)

0 commit comments

Comments
 (0)