完成了分享下载全部流程

This commit is contained in:
2024-10-12 13:37:49 +08:00
parent e6f5aaa02f
commit 7862b1d88e
11 changed files with 342 additions and 30 deletions
+6 -4
View File
@@ -5,37 +5,39 @@ import (
"fmt"
"github.com/grandcat/zeroconf"
"net"
"work_cation/cfg"
)
// Online 在线数据
type Online struct {
AddrIPv4 []net.IP `json:"-"` // Host machine IPv4 address
AddrIPv6 []net.IP `json:"-"`
Port int `json:"port"`
Port string `json:"port"`
ID string `json:"id"`
Ip string `json:"ip"`
}
func (o *Online) Url(router string) string {
return fmt.Sprintf("http://%s:%d%s", o.Ip, o.Port, router)
return fmt.Sprintf("http://%s%s%s", o.Ip, o.Port, router)
}
func UserTOnlineList(user *Users) []string {
return []string{
user.ID,
user.Ip,
cfg.T.ServerAddr,
}
}
func NewOnline(entry *zeroconf.ServiceEntry) (*Online, error) {
if len(entry.Text) != 2 {
if len(entry.Text) != 3 {
return nil, errors.New("invalid online entry")
}
return &Online{
AddrIPv4: entry.AddrIPv4,
AddrIPv6: entry.AddrIPv6,
Port: entry.Port,
Port: entry.Text[2],
ID: entry.Text[0],
Ip: entry.Text[1],
}, nil