本文整理匯總了Golang中packet.PacketStd.SendFilePacket方法的典型用法代碼示例。如果您正苦於以下問題:Golang PacketStd.SendFilePacket方法的具體用法?Golang PacketStd.SendFilePacket怎麽用?Golang PacketStd.SendFilePacket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類packet.PacketStd
的用法示例。
在下文中一共展示了PacketStd.SendFilePacket方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: pullHandler
func (fs *FileSession) pullHandler(incomingPacket packet.PacketStd) {
if incomingPacket.Name == "REQ_FILELIST" {
//db initializing
db, error := sql.Open("sqlite3", "../gypo.db")
//tells client pull request recieved
newPacket := packet.PacketStd{packet.Packet{"pull", "REQ_FILELIST_RECV"}, ""}
go newPacket.SendPacket(fs.Connection)
//creates list of server files and sends back to client
if error != nil {
fmt.Println(error.Error())
} else {
//PacketList instance for server files(db)
var server_fileList packet.PacketList
//get number of files from db to use for file server_fileList.Data size
var dbFileCount int
error = db.QueryRow("SELECT count(*) AS number FROM files WHERE user_id = ?", fs.User.Id).Scan(&dbFileCount)
if error != nil {
fmt.Println(error.Error())
} else {
//sets PacketList instance variables
server_fileList.Data = make([]packet.PacketStd, dbFileCount)
server_fileList.ContentType = "pull"
server_fileList.Name = "RESP_FILELIST"
//get fileList from db
rows, error := db.Query("SELECT filename, path, hash, is_dir FROM files WHERE user_id = ?", fs.User.Id)
if error != nil {
fmt.Println(error.Error())
} else {
var rowPacket packet.PacketStd
var filename, path, hash string
var is_dir int
i := 0
for rows.Next() {
error = rows.Scan(&filename, &path, &hash, &is_dir)
if error != nil {
fmt.Println(error.Error())
} else {
if is_dir == 1 {
rowPacket.ContentType = "folder"
rowPacket.Name = path
rowPacket.Data = ""
} else {
rowPacket.ContentType = "hash"
rowPacket.Name = path + filename
rowPacket.Data = hash
}
}
server_fileList.Data[i] = rowPacket
i++
}
go server_fileList.SendPacket(fs.Connection)
fmt.Println("server_fileList size: ", len(server_fileList.Data))
}
}
}
} else if incomingPacket.Name == "REQ_FILE" {
//wraps file in packet and sends it
newPacket := packet.PacketStd{packet.Packet{"pull", "RESP_FILE"}, incomingPacket.Data}
go newPacket.SendFilePacket(fs.Connection)
}
}