Пример #1
0
func main() {

	ConnMap = make(pac.ConnMapType)

	ln, err := pac.Listen("127.0.0.1:8080")

	defer ln.Close()
	pac.CheckError(err)
	fmt.Println("server starting...")

	param := ConnParam

	dbconn, err := DB.Connect(param)
	defer dbconn.Close()
	pac.CheckError(err)

	_, err = dbconn.Execute("USE " + param.DbName)
	pac.CheckError(err)

	for {
		conn, err := ln.AcceptTCP()
		pac.CheckError(err)

		ConnMap[conn.RemoteAddr().String()] = conn

		go handleConnection(conn, dbconn)
	}
}
Пример #2
0
func main() {
	var tcpAddr *net.TCPAddr
	ConnMap = make(map[string]*net.TCPConn)
	tcpAddr, _ = net.ResolveTCPAddr("tcp", "127.0.0.1:8080")

	ln, err := net.ListenTCP("tcp", tcpAddr)
	defer ln.Close()
	checkError(err)
	fmt.Println("server starting...")

	param := ConnParam

	dbconn, err := DB.Connect(param)
	defer dbconn.Close()
	checkError(err)

	_, err = dbconn.Execute("USE " + param.DbName)
	checkError(err)

	for {
		conn, err := ln.AcceptTCP()
		checkError(err)

		ConnMap[conn.RemoteAddr().String()] = conn

		go handleConnection(conn, dbconn)
	}
}
Пример #3
0
func main() {

	param := ConnParam
	param.DbName = "chat"

	conn, err := DB.Connect(param)
	defer conn.Close()
	checkError(err)

	_, err = conn.Execute("USE " + param.DbName)
	checkError(err)

	_, err = conn.Execute(`CREATE TABLE test (
		id INT PRIMARY KEY,
		value VARCHAR(10)
	)`)
	checkError(err)

	for i := 0; i < 10; i++ {
		_, err := conn.Execute("INSERT INTO test VALUES(" + strconv.Itoa(i) + ",'" + strconv.Itoa(i) + "')")
		checkError(err)
	}

}