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 ./...
|
go vet ./...
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test -v ./...
|
go test -count=1 -v ./...
|
||||||
|
|
||||||
build: generate vet
|
build: generate vet
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
|
@ -213,13 +213,13 @@ func setupWebSockets(admin *matchmaker.MatchMaker, websessions *ui.WebSessions)
|
|||||||
sessionService := websocketutil.WebSocketService{
|
sessionService := websocketutil.WebSocketService{
|
||||||
Handler: func(w http.ResponseWriter, r *http.Request, conn net.Conn) {
|
Handler: func(w http.ResponseWriter, r *http.Request, conn net.Conn) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
websession := websessions.NewSession(conn, ctx, cancel)
|
websession := websessions.NewSession(ctx, cancel, conn)
|
||||||
defer websessions.SessionClosed(websession)
|
defer websessions.SessionClosed(websession)
|
||||||
location, err := ui.GetUserLocation(r)
|
location, err := ui.GetUserLocation(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
websession.WriteNotifications(location, ctx, cancel)
|
websession.WriteNotifications(ctx, cancel, location)
|
||||||
},
|
},
|
||||||
Text: true,
|
Text: true,
|
||||||
}
|
}
|
||||||
|
@ -69,8 +69,7 @@ func (sessions *WebSessions) notifyWebSessions(notification *models.State) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sessions *WebSessions) NewSession(wsConnection net.Conn, ctx context.Context,
|
func (sessions *WebSessions) NewSession(ctx context.Context, cancel context.CancelFunc, wsConnection net.Conn) *WebSession {
|
||||||
cancel context.CancelFunc) *WebSession {
|
|
||||||
sessions.mutex.Lock()
|
sessions.mutex.Lock()
|
||||||
defer sessions.mutex.Unlock()
|
defer sessions.mutex.Unlock()
|
||||||
session := &WebSession{
|
session := &WebSession{
|
||||||
@ -108,7 +107,7 @@ func (sessions *WebSessions) NewSession(wsConnection net.Conn, ctx context.Conte
|
|||||||
return session
|
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)
|
timer := time.NewTicker(10 * time.Second)
|
||||||
defer timer.Stop()
|
defer timer.Stop()
|
||||||
// if for some reason we cannot send notifications to the web client then the context is canceled.
|
// 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