<commit_before>package main

import (
	"net/http"
	"os"
	"fmt"
	"github.com/apsdehal/go-logger"
	"github.com/gin-gonic/gin"
	"github.com/gorilla/websocket"
)

var connections [10]*websocket.Conn;
var size int = 0;

func main() {
	router := gin.Default()
	router.GET("/version", version)
	router.GET("/ws/echo", func(c *gin.Context) {
        echo(c.Writer, c.Request)
    })
	router.Run(":8080")
}

func version(c *gin.Context) {
	c.JSON(http.StatusOK, gin.H{ "version": "1.0.0" })
}

var wsupgrader = websocket.Upgrader{
    ReadBufferSize:  1024,
    WriteBufferSize: 1024,
		CheckOrigin: func(r *http.Request) bool { return true },
}

func echo(w http.ResponseWriter, r *http.Request){
	conn, err := wsupgrader.Upgrade(w, r, nil)
	    if err != nil {
	        fmt.Printf("Failed to set websocket upgrade: %+v \n", err)
	        return
	    }
			connections[size] = conn
			size ++
	    for {
	        t, msg, err := conn.ReadMessage()
	        if err != nil {
	            break
	        }
					for i := 0; i < size ; i ++ {
							connections[i].WriteMessage(t, msg)
					}
	    }
			for i := 0; i < size ; i ++ {
				if conn == connections[i] {
					size --
					connections[i] = nil
				}
			}
}

func getLogger() *logger.Logger {
	log, err := logger.New("LOG", 1, os.Stdout)
	if err != nil {<commit_msg>Better management connections to Websocket<commit_after>package main

import (
	"net/http"
	"os"
	"fmt"
	"github.com/apsdehal/go-logger"
	"github.com/gin-gonic/gin"
	"github.com/gorilla/websocket"
)

var connections map[*websocket.Conn]bool;

func main() {
	connections = make(map[*websocket.Conn]bool)
	router := gin.Default()
	router.GET("/version", version)
	router.GET("/ws/echo", func(c *gin.Context) {
		echo(c.Writer, c.Request)
	})
	router.Run(":8080")
}

func version(c *gin.Context) {
	c.JSON(http.StatusOK, gin.H{"version": "1.0.0" })
}

var wsupgrader = websocket.Upgrader{
	ReadBufferSize:  1024,
	WriteBufferSize: 1024,
	CheckOrigin: func(r *http.Request) bool {
		return true
	},
}

func echo(w http.ResponseWriter, r *http.Request) {
	conn, err := wsupgrader.Upgrade(w, r, nil)
	if err != nil {
		//noinspection GoPlaceholderCount
		fmt.Printf("Failed to set websocket upgrade: %+v \n", err)
		return
	}
	defer
	func() {
		delete(connections, conn)
		conn.Close()
	}()
	connections[conn] = true
	for {
		t, msg, err := conn.ReadMessage()
		if err != nil {
			break
		}
		for key, _ := range connections {
			key.WriteMessage(t, msg)
		}
	}
}

func getLogger() *logger.Logger {
	log, err := logger.New("LOG", 1, os.Stdout)
	if err != nil {
{'fraction_non_alphanumeric': 0.16497659906396256, 'fraction_numerical': 0.014430577223088924, 'mean_word_length': 3.0843949044585988, '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': '6939591', 'n_tokens_mistral': 1075, 'n_tokens_neox': 969, 'n_words': 219}