<commit_before>package socket

import (
    "time"
    "net/http"
    "github.com/gorilla/websocket"
    "app/hub"
    "app/message"
)

var upgrader = websocket.Upgrader{}

func writeSocket(socket *websocket.Conn, c hub.Connection)  {
    defer socket.Close()
    for {
        m := <- c.Out
        socket.WriteJSON(&m)
    }
}

// Handler handles websocket connections at /ws
func Handler(w http.ResponseWriter, r *http.Request) {
    socket, err := upgrader.Upgrade(w, r, nil)
	if err != nil {
        panic(err)
	}
	defer socket.Close()

    c := hub.NewConnection()

    go writeSocket(socket, c)

    for {
        m := message.SocketMessage{}
        m.CreatedAt = time.Now().UTC()

		socket.ReadJSON(&m)

        if m.Action == "publish" {
            hub.Publish(m)
        }

        if m.Action == "subscribe" {
            hub.Subscribe(m.Event, c)
        }

        if m.Action == "unsubscribe" {
            hub.Unsubscribe(m.Event, c)
        }

        if m.Action == "unsubscribe:all" {
            hub.UnsubscribeAll(c)
        }
	}
}
<commit_msg>We have switch in golang<commit_after>package socket

import (
    "time"
    "net/http"
    "github.com/gorilla/websocket"
    "app/hub"
    "app/message"
)

var upgrader = websocket.Upgrader{}

func writeSocket(socket *websocket.Conn, c hub.Connection)  {
    defer socket.Close()
    for {
        m := <- c.Out
        socket.WriteJSON(&m)
    }
}

// Handler handles websocket connections at /ws
func Handler(w http.ResponseWriter, r *http.Request) {
    socket, err := upgrader.Upgrade(w, r, nil)
	if err != nil {
        panic(err)
	}
	defer socket.Close()

    c := hub.NewConnection()

    go writeSocket(socket, c)

    for {
        m := message.SocketMessage{}
        m.CreatedAt = time.Now().UTC()

		socket.ReadJSON(&m)

        switch m.Action {
        case "publish":
            hub.Publish(m)
        case "subscribe":
            hub.Subscribe(m.Event, c)
        case "unsubscribe":
            hub.Unsubscribe(m.Event, c)
        case "unsubscribe:all":
            hub.UnsubscribeAll(c)
        }
	}
}

{'fraction_non_alphanumeric': 0.13432122370936903, 'fraction_numerical': 0.0, 'mean_word_length': 2.0202020202020203, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6398091', 'n_tokens_mistral': 725, 'n_tokens_neox': 695, 'n_words': 148}