本文整理匯總了Golang中github.com/organ/golibtox.Tox類的典型用法代碼示例。如果您正苦於以下問題:Golang Tox類的具體用法?Golang Tox怎麽用?Golang Tox使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Tox類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: onFriendRequest
func onFriendRequest(t *golibtox.Tox, publicKey []byte, data []byte, length uint16) {
name, _ := t.GetSelfName()
fmt.Printf("[%s] New friend request from %s\n", name, hex.EncodeToString(publicKey))
// Auto-accept friend request
t.AddFriendNorequest(publicKey)
}
示例2: onFileSendRequest
func onFileSendRequest(t *golibtox.Tox, friendnumber int32, filenumber uint8, filesize uint64, filename []byte, filenameLength uint16) {
// Accept any file send request
t.FileSendControl(friendnumber, true, filenumber, golibtox.FILECONTROL_ACCEPT, nil)
// Init *File handle
f, _ := os.Create("example_" + string(filename))
// Append f to the map[uint8]*os.File
transfers[filenumber] = f
}
示例3: onFileControl
func onFileControl(t *golibtox.Tox, friendnumber int32, sending bool, filenumber uint8, fileControl golibtox.FileControl, data []byte, length uint16) {
// Finished receiving file
if fileControl == golibtox.FILECONTROL_FINISHED {
f := transfers[filenumber]
f.Sync()
f.Close()
delete(transfers, filenumber)
fmt.Println("Written file", filenumber)
t.SendMessage(friendnumber, []byte("Thanks!"))
}
}
示例4: saveData
func saveData(t *golibtox.Tox, filepath string) error {
if len(filepath) == 0 {
return errors.New("Empty path")
}
data, err := t.Save()
if err != nil {
return err
}
err = ioutil.WriteFile(filepath, data, 0644)
return err
}
示例5: loadData
func loadData(t *golibtox.Tox, filepath string) error {
if len(filepath) == 0 {
return errors.New("Empty path")
}
data, err := ioutil.ReadFile(filepath)
if err != nil {
return err
}
err = t.Load(data)
return err
}
示例6: onFriendMessage
func onFriendMessage(t *golibtox.Tox, friendnumber int32, message []byte, length uint16) {
fmt.Printf("New message from %d : %s\n", friendnumber, string(message))
// Echo back
t.SendMessage(friendnumber, message)
}
示例7: onFriendRequest
func onFriendRequest(t *golibtox.Tox, publicKey []byte, data []byte, length uint16) {
fmt.Printf("New friend request from %s\n", hex.EncodeToString(publicKey))
fmt.Printf("With message: %v\n", string(data))
// Auto-accept friend request
t.AddFriendNorequest(publicKey)
}
示例8: onFriendMessage
func onFriendMessage(t *golibtox.Tox, friendnumber int32, message []byte, length uint16) {
name, _ := t.GetSelfName()
friend, _ := t.GetName(friendnumber)
fmt.Printf("[%s] New message from %s : %s\n", name, friend, string(message))
}