完善个人数据维护, 初步建立局域网链接逻辑
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/grandcat/zeroconf"
|
||||
"net"
|
||||
)
|
||||
|
||||
// Online 在线数据
|
||||
type Online struct {
|
||||
AddrIPv4 []net.IP `json:"-"` // Host machine IPv4 address
|
||||
AddrIPv6 []net.IP `json:"-"`
|
||||
Port int `json:"port"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"` // 昵称
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
Email string `json:"email"`
|
||||
Phone string `json:"phone"`
|
||||
Address string `json:"address"` // 工位
|
||||
}
|
||||
|
||||
func UserTOnlineList(user *Users) []string {
|
||||
return []string{
|
||||
user.ID,
|
||||
user.Name,
|
||||
user.Avatar,
|
||||
user.Email,
|
||||
user.Phone,
|
||||
user.Address,
|
||||
}
|
||||
}
|
||||
|
||||
func NewOnline(entry *zeroconf.ServiceEntry) (*Online, error) {
|
||||
if len(entry.Text) != 6 {
|
||||
return nil, errors.New("invalid online entry")
|
||||
}
|
||||
return &Online{
|
||||
AddrIPv4: entry.AddrIPv4,
|
||||
AddrIPv6: entry.AddrIPv6,
|
||||
Port: entry.Port,
|
||||
ID: entry.Text[0],
|
||||
Name: entry.Text[1],
|
||||
Avatar: entry.Text[2],
|
||||
Email: entry.Text[3],
|
||||
Phone: entry.Text[4],
|
||||
Address: entry.Text[5],
|
||||
}, nil
|
||||
}
|
||||
+1
-1
@@ -8,5 +8,5 @@ type Users struct {
|
||||
Cover string `json:"cover"` // 封面
|
||||
Email string `json:"email"`
|
||||
Phone string `json:"phone"`
|
||||
Address string `json:"address"`
|
||||
Address string `json:"address"` // 工位
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user