Skip to content

Commit

Permalink
fix: 修改一些bug
Browse files Browse the repository at this point in the history
  • Loading branch information
czx-lab committed Jun 5, 2024
1 parent 5c5adc5 commit d31e58f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
8 changes: 4 additions & 4 deletions internal/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ type Interface interface {
var smap sync.Map

type Event struct {
wg sync.WaitGroup
wg *sync.WaitGroup
}

func New() *Event {
return &Event{
wg: sync.WaitGroup{},
wg: new(sync.WaitGroup),
}
}

Expand Down Expand Up @@ -88,10 +88,10 @@ func (e *Event) exec(handlers []Interface, event EventInterface, async bool) err
for _, handler := range handlers {
e.wg.Add(1)
execFunc := handler
go func(wg *sync.WaitGroup) {
go func() {
defer e.wg.Done()
execFunc.Process(param)
}(&e.wg)
}()
}
e.wg.Wait()
return nil
Expand Down
5 changes: 2 additions & 3 deletions internal/server/websocket/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package server

import (
"errors"
"fmt"
"log"
"net/http"
Expand Down Expand Up @@ -41,7 +40,7 @@ func NewSocketClient(ctx *gin.Context, key string, socket *Socket) *SocketClient
func (s *SocketClient) readPump() {
defer func() {
if err := recover(); err != nil {
s.socket.opts.handler.OnError(s.key, errors.New(fmt.Sprintf("%v", err)))
s.socket.opts.handler.OnError(s.key, fmt.Errorf("%v", err))
}
s.close()
}()
Expand Down Expand Up @@ -73,7 +72,7 @@ func (s *SocketClient) writePump() {
ticker := time.NewTicker(s.socket.opts.pingPeriod)
defer func() {
if err := recover(); err != nil {
s.socket.opts.handler.OnError(s.key, errors.New(fmt.Sprintf("%v", err)))
s.socket.opts.handler.OnError(s.key, fmt.Errorf("%v", err))
}
s.close()
}()
Expand Down
2 changes: 1 addition & 1 deletion internal/server/websocket/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (s *Socket) WriteMessage(message Message) error {
} else {
for _, key := range message.Subkeys {
client, ok := s.clients[key]
if !ok && client.state == OffLineState {
if !ok || client.state == OffLineState {
return errors.New("Connect does not exist")
}
client.send <- message.Data
Expand Down
3 changes: 1 addition & 2 deletions test/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package test

import (
"fmt"
"testing"

"skeleton/internal/server"
"skeleton/router"
"testing"

"github.com/gin-gonic/gin"
)
Expand Down

0 comments on commit d31e58f

Please sign in to comment.