Ejemplo n.º 1
0
func handleConnection(c net.Conn) {
	logger.LogI("New connection from " + c.RemoteAddr().String())
	defer c.Close()

	request, err := readRequestData(c)

	if err != nil {
		return
	}

	response := generateResponse(request.Method, request.Path)
	c.Write(response.Bytes())
}
Ejemplo n.º 2
0
func main() {
	listenParams := fmt.Sprintf("%s:%d", configuration.Host, configuration.Port)
	logger.LogI("Server started on " + listenParams)

	for _, v := range closers {
		defer v.Close()
	}

	listener, err := net.Listen("tcp", listenParams)
	if err != nil {
		logger.LogE(err)
	}

	for {
		conn, err := listener.Accept()

		if err != nil {
			logger.LogE(err)
		}

		go handleConnection(conn)
	}
}