1
0
mirror of https://github.com/fumiama/go-registry.git synced 2026-06-08 18:10:34 +08:00

remove zb deps

This commit is contained in:
fumiama
2022-02-10 14:09:02 +08:00
parent 88a399835e
commit dce9486873
5 changed files with 46 additions and 76 deletions

5
go.mod
View File

@@ -2,7 +2,4 @@ module github.com/fumiama/go-registry
go 1.17
require (
github.com/fumiama/gofastTEA v0.0.6
github.com/wdvxdr1123/ZeroBot v1.4.1
)
require github.com/fumiama/gofastTEA v0.0.7

60
go.sum
View File

@@ -1,58 +1,2 @@
github.com/Mrs4s/MiraiGo v0.0.0-20211120033824-43b23f4e6fcb h1:Rkj28fqIwGx/EgBzRYtpmJRfH6wqVn7cNdc7aJ0QE4M=
github.com/Mrs4s/MiraiGo v0.0.0-20211120033824-43b23f4e6fcb/go.mod h1:imVKbfKqqeit+C/eaWGb4MKQ3z3gN6pRpBU5RMtp5so=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fumiama/gofastTEA v0.0.6 h1:Yni3MXDbJVa/c4CecgdZDgCJK+fLdvGph+OBqY2mtiI=
github.com/fumiama/gofastTEA v0.0.6/go.mod h1:+sBZ05nCA2skZkursHNvyr8kULlEetrYTM2y5kA4rQc=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go.mod h1:tzym/CEb5jnFI+Q0k4Qq3+LvRF4gO3E2pxS8fHP8jcA=
github.com/tidwall/gjson v1.11.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/wdvxdr1123/ZeroBot v1.4.1 h1:fk/8RH2D1gB3YeC1eI/SZi/kG31Rh7Z8lAiDc60VZFM=
github.com/wdvxdr1123/ZeroBot v1.4.1/go.mod h1:7t9m4vDZPwWAmzKlhP6IvUoisOIiqNdm/3AJgiY3+ew=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
github.com/fumiama/gofastTEA v0.0.7 h1:Dbce+22jNm+7jpmAeju0C+esIAAnIrq75f5TsCYprS8=
github.com/fumiama/gofastTEA v0.0.7/go.mod h1:RIdbYZyB4MbH6ZBlPymRaXn3cD6SedlCu5W/HHfMPBk=

30
helper.go Normal file
View File

@@ -0,0 +1,30 @@
package registry
import "unsafe"
// slice is the runtime representation of a slice.
// It cannot be used safely or portably and its representation may
// change in a later release.
//
// Unlike reflect.SliceHeader, its Data field is sufficient to guarantee the
// data it references will not be garbage collected.
type slice struct {
Data unsafe.Pointer
Len int
Cap int
}
// BytesToString 没有内存开销的转换
func BytesToString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
// StringToBytes 没有内存开销的转换
func StringToBytes(s string) (b []byte) {
bh := (*slice)(unsafe.Pointer(&b))
sh := (*slice)(unsafe.Pointer(&s))
bh.Data = sh.Data
bh.Len = sh.Len
bh.Cap = sh.Len
return b
}

23
reg.go
View File

@@ -6,7 +6,6 @@ import (
"time"
tea "github.com/fumiama/gofastTEA"
"github.com/wdvxdr1123/ZeroBot/utils/helper"
)
type Regedit struct {
@@ -26,8 +25,8 @@ func NewRegedit(addr, pwd, sps string) *Regedit {
if len(sps) > 15 {
sps = sps[:15]
}
copy(tp[:], helper.StringToBytes(pwd))
copy(ts[:], helper.StringToBytes(sps))
copy(tp[:], StringToBytes(pwd))
copy(ts[:], StringToBytes(sps))
s := tea.NewTeaCipherLittleEndian(ts[:])
return &Regedit{addr: addr, tp: tea.NewTeaCipherLittleEndian(tp[:]), ts: &s}
}
@@ -37,7 +36,7 @@ func NewRegReader(addr, pwd string) *Regedit {
if len(pwd) > 15 {
pwd = pwd[:15]
}
copy(tp[:], helper.StringToBytes(pwd))
copy(tp[:], StringToBytes(pwd))
return &Regedit{addr: addr, tp: tea.NewTeaCipherLittleEndian(tp[:])}
}
@@ -62,7 +61,7 @@ func (r *Regedit) Get(key string) (string, error) {
if len(key) > 127 {
return "", errors.New("get key too long")
}
p := NewCmdPacket(CMDGET, helper.StringToBytes(key), &r.tp)
p := NewCmdPacket(CMDGET, StringToBytes(key), &r.tp)
r.conn.Write(p.Encrypt(r.seq))
r.seq++
ack, err := r.ack()
@@ -73,7 +72,7 @@ func (r *Regedit) Get(key string) (string, error) {
if ackbytes == nil {
return "", errors.New("decrypt ack error")
}
a := helper.BytesToString(ackbytes)
a := BytesToString(ackbytes)
r.seq++
if a == "erro" {
return "", errors.New("server ack error")
@@ -94,7 +93,7 @@ func (r *Regedit) Set(key, value string) error {
if len(value) > 127 {
return errors.New("set val too long")
}
p := NewCmdPacket(CMDSET, helper.StringToBytes(key), r.ts)
p := NewCmdPacket(CMDSET, StringToBytes(key), r.ts)
r.conn.Write(p.Encrypt(r.seq))
r.seq++
ack, err := r.ack()
@@ -105,7 +104,7 @@ func (r *Regedit) Set(key, value string) error {
if ackbytes == nil {
return errors.New("decrypt ack error")
}
a := helper.BytesToString(ackbytes)
a := BytesToString(ackbytes)
r.seq++
if a == "erro" {
return errors.New("server ack error")
@@ -113,7 +112,7 @@ func (r *Regedit) Set(key, value string) error {
if a != "data" {
return errors.New("unknown ack error")
}
p = NewCmdPacket(CMDDAT, helper.StringToBytes(value), r.ts)
p = NewCmdPacket(CMDDAT, StringToBytes(value), r.ts)
r.conn.Write(p.Encrypt(r.seq))
r.seq++
ack, err = r.ack()
@@ -124,7 +123,7 @@ func (r *Regedit) Set(key, value string) error {
if ackbytes == nil {
return errors.New("decrypt ack error")
}
a = helper.BytesToString(ackbytes)
a = BytesToString(ackbytes)
r.seq++
if a == "erro" {
return errors.New("server ack error")
@@ -142,7 +141,7 @@ func (r *Regedit) Del(key string) error {
if len(key) > 127 {
return errors.New("get key too long")
}
p := NewCmdPacket(CMDDEL, helper.StringToBytes(key), r.ts)
p := NewCmdPacket(CMDDEL, StringToBytes(key), r.ts)
r.conn.Write(p.Encrypt(r.seq))
r.seq++
ack, err := r.ack()
@@ -153,7 +152,7 @@ func (r *Regedit) Del(key string) error {
if ackbytes == nil {
return errors.New("decrypt ack error")
}
a := helper.BytesToString(ackbytes)
a := BytesToString(ackbytes)
r.seq++
if a == "erro" {
return errors.New("server ack error")

View File

@@ -40,13 +40,13 @@ func TestReg(t *testing.T) {
}
func TestPush(t *testing.T) {
r := NewRegedit("reilia.eastasia.azurecontainer.io:32664", "fumiama", "--")
r := NewRegedit("reilia.fumiama.top:32664", "fumiama", "--")
err := r.Connect()
if err != nil {
t.Fatal(err)
}
/*
err = r.Set("ZeroBot-Plugin/kanban", "QQ群:1048452984, 开发群:705749886. 禁止用于商业用途")
err = r.Set("ZeroBot-Plugin/kanban", "QQ群:1048452984, 开发群:705749886. 禁止用于商业用途.\nv1.2.2及以下版本公告服将在2月下线.")
if err != nil {
t.Fatal(err)
}