func (c *connection) writePump() {
	ticker := time.NewTicker(pingPeriod)
	defer func() {
		ticker.Stop()
		util.LogError(c.ws.Close())
	}()
	for {
		select {
		case message, ok := <-c.send:
			if !ok {
				util.LogError(c.write(websocket.CloseMessage, []byte{}))
				return
			}
			if err := c.write(websocket.TextMessage, message); err != nil {
				util.LogError(err)
				return
			}
		case <-ticker.C:
			if err := c.write(websocket.PingMessage, []byte{}); err != nil {
				util.LogError(err)
				return
			}
		}
	}
}
writePump pumps messages from the hub to the websocket connection.
package sockets
import (
	"fmt"
	"github.com/ansible-semaphore/semaphore/db"
	"net/http"
	"time"
	log "github.com/Sirupsen/logrus"
	"github.com/ansible-semaphore/semaphore/util"
	"github.com/gorilla/context"
	"github.com/gorilla/websocket"
)
var upgrader = websocket.Upgrader{
	ReadBufferSize:  1024,
	WriteBufferSize: 1024,
	CheckOrigin: func(r *http.Request) bool {
		return true
	},
}
const (
	writeWait = 10 * time.Second
	pongWait = 60 * time.Second
	pingPeriod = (pongWait * 9) / 10
	maxMessageSize = 512
)
type connection struct {
	ws     *websocket.Conn
	send   chan []byte
	userID int
}
func (c *connection) readPump() {
	defer func() {
		h.unregister <- c
		util.LogErrorWithFields(c.ws.Close(), log.Fields{"error": "Error closing websocket"})
	}()
	c.ws.SetReadLimit(maxMessageSize)
	util.LogErrorWithFields(c.ws.SetReadDeadline(time.Now().Add(pongWait)), log.Fields{"error": "Socket state corrupt"})
	c.ws.SetPongHandler(func(string) error {
		util.LogErrorWithFields(c.ws.SetReadDeadline(time.Now().Add(pongWait)), log.Fields{"error": "Socket state corrupt"})
		return nil
	})
	for {
		_, message, err := c.ws.ReadMessage()
		fmt.Println(string(message))
		if err != nil {
			if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway) {
				util.LogError(err)
			}
			break
		}
	}
}
func (c *connection) write(mt int, payload []byte) error {
	util.LogErrorWithFields(c.ws.SetWriteDeadline(time.Now().Add(writeWait)), log.Fields{"error": "Socket state corrupt"})
	return c.ws.WriteMessage(mt, payload)
}