1. Heartbeat Pack: The heartbeat packet is sent to continuously monitor and send the effect of reaching long connection
2. Handling connections to MySQL and SQLite
3.KCP go here to download kcp-go
4.protoc.exe go here to download protoc-3.6.0-win32.zip
5.bat Regular expression preceded by a REM indicating that the next regular match
@echo off
ECHO is building go code ...
REM protoc-i=./--go_out=. /pb/. \messageid.proto
Pause
Handling connections to MySQL and SQLite
Package Conntest
Import (
"Database/sql"
"FMT"
_ "Github.com/go-sql-driver/mysql"
_ "Github.com/mattn/go-sqlite3"
"OS"
"Testing"
)
Func testmysqlconn (t *testing. T) {
DB, err: = SQL. Open ("MySQL", "root:huhao123@tcp (127.0.0.1:3306)/game?charset=utf8")
If err! = Nil {
Fmt. PRINTLN (ERR)
Return
}
Defer db. Close ()
var result sql. Result
result, err = db. Exec ("INSERT into user_table (user_id, Name,password) VALUES (?,?,?)", 1234, "Huhaos", "huhao123")
If err! = Nil {
Fmt. PRINTLN (ERR)
Return
}
LastID, _: = result. Lastinsertid ()
Fmt. PRINTLN ("The ID of the newly inserted record is", LastID)
var row *sql. Row
row = db. Queryrow ("SELECT * from User_table")
var name, passwordstring
var user_idint
Err = row. Scan (&user_id, &password, &name)
If err! = Nil {
Fmt. PRINTLN (ERR)
Return
}
Fmt. Println (user_id, "\ T", name, "\ T", password)
result, err = db. Exec ("INSERT into user_table (User_id,name,password) VALUES (?,?,?)", 4444, "Black", "huhao123456")
var rows *sql. Rows
rows, err = db. Query ("SELECT * from User_table")
If err! = Nil {
Fmt. PRINTLN (ERR)
Return
}
For rows. Next () {
var name, passwordstring
var user_idint
Rows. Scan (&user_id, &name, &password)
Fmt. Println (user_id, "\ T", name, "\ T", password)
}
Rows. Close ()
Db. Exec ("TRUNCATE TABLE user")
}
Func testsqliteconn (t *testing. T) {
Dbconnector, err: = SQL. Open ("Sqlite3", "./... /db/sqllite.db ")
If err! = Nil | | Dbconnector = = Nil {
Fmt. Printf ("Connection Failed")
Os. Exit (1)
}
Dbconnector.setmaxopenconns (16)
Dbconnector.setmaxidleconns (8)
P: = dbconnector.ping ()
Fmt. Printf ("Connection succeeded%v", p)
SqlString: =string ("replace into user_table (User_id,name,password) VALUES (?,?,?)")
stmt, err__: = Dbconnector.prepare (SqlString)
Defer stmt. Close ()
If err__! = Nil {
Fmt. PRINTLN ("Create Err", err__)
Return
}
result, err: = stmt. Exec (
33334,
"Huhao",
"Huhao123",
)
If err! = Nil {
Fmt. PRINTLN ("Create err", err)
}
Effectrow, err: = result. Rowsaffected ()
If err! = Nil {
Fmt. PRINTLN ("Create err", err)
}
Fmt. PRINTLN ("Create Effect rows:", Effectrow)
}
Func testredisconn (t *testing. T) {
}