本文整理汇总了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))
}