示例#1
0
文件: main.go 项目: dimorinny/dimginx
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())
}
示例#2
0
文件: main.go 项目: dimorinny/dimginx
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)
	}
}