go conventions: context should be first argument.
This commit is contained in:
parent
60cda211ef
commit
a62a513105
2
Makefile
2
Makefile
@ -14,7 +14,7 @@ vet: fmt
|
||||
go vet ./...
|
||||
|
||||
test:
|
||||
go test -v ./...
|
||||
go test -count=1 -v ./...
|
||||
|
||||
build: generate vet
|
||||
mkdir -p bin
|
||||
|
@ -213,13 +213,13 @@ func setupWebSockets(admin *matchmaker.MatchMaker, websessions *ui.WebSessions)
|
||||
sessionService := websocketutil.WebSocketService{
|
||||
Handler: func(w http.ResponseWriter, r *http.Request, conn net.Conn) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
websession := websessions.NewSession(conn, ctx, cancel)
|
||||
websession := websessions.NewSession(ctx, cancel, conn)
|
||||
defer websessions.SessionClosed(websession)
|
||||
location, err := ui.GetUserLocation(r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
websession.WriteNotifications(location, ctx, cancel)
|
||||
websession.WriteNotifications(ctx, cancel, location)
|
||||
},
|
||||
Text: true,
|
||||
}
|
||||
|
@ -69,8 +69,7 @@ func (sessions *WebSessions) notifyWebSessions(notification *models.State) {
|
||||
}
|
||||
}
|
||||
|
||||
func (sessions *WebSessions) NewSession(wsConnection net.Conn, ctx context.Context,
|
||||
cancel context.CancelFunc) *WebSession {
|
||||
func (sessions *WebSessions) NewSession(ctx context.Context, cancel context.CancelFunc, wsConnection net.Conn) *WebSession {
|
||||
sessions.mutex.Lock()
|
||||
defer sessions.mutex.Unlock()
|
||||
session := &WebSession{
|
||||
@ -108,7 +107,7 @@ func (sessions *WebSessions) NewSession(wsConnection net.Conn, ctx context.Conte
|
||||
return session
|
||||
}
|
||||
|
||||
func (session *WebSession) WriteNotifications(location *time.Location, ctx context.Context, cancel context.CancelFunc) {
|
||||
func (session *WebSession) WriteNotifications(ctx context.Context, cancel context.CancelFunc, location *time.Location) {
|
||||
timer := time.NewTicker(10 * time.Second)
|
||||
defer timer.Stop()
|
||||
// if for some reason we cannot send notifications to the web client then the context is canceled.
|
||||
|
Loading…
Reference in New Issue
Block a user