-
Notifications
You must be signed in to change notification settings - Fork 17
/
pool.go
59 lines (52 loc) · 1.12 KB
/
pool.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package pool
import (
"errors"
"time"
"github.com/fumiama/go-registry"
"github.com/FloatTech/floatbox/process"
)
type item struct {
name string
u string
}
// newItem 唯一标识文件名 文件链接
func newItem(name, u string) (*item, error) {
if len(name) > 126 {
return nil, errors.New("name too long")
}
if len(u) > 126 {
return nil, errors.New("url too long")
}
return &item{name: name, u: u}, nil
}
// getItem 唯一标识文件名
func getItem(name string) (*item, error) {
reg := registry.NewRegReader("reilia.fumiama.top:35354", "", "fumiama")
err := reg.ConnectIn(time.Second * 4)
if err != nil {
return nil, err
}
u, err := reg.Get(name)
defer reg.Close()
if err != nil {
return nil, err
}
return &item{name: name, u: u}, nil
}
// push 推送 item
func (t *item) push(key string) (err error) {
for i := 0; i < 8; i++ {
r := registry.NewRegedit("reilia.fumiama.top:35354", "", "fumiama", key)
err = r.ConnectIn(time.Second * 8)
if err != nil {
return
}
err = r.Set(t.name, t.u)
_ = r.Close()
if err == nil {
break
}
process.SleepAbout1sTo2s() // 随机退避
}
return
}