github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/node/subscribe.go (about) 1 package node 2 3 import ( 4 "context" 5 6 gn "github.com/Asutorufa/yuhaiin/pkg/protos/node/grpc" 7 "google.golang.org/protobuf/types/known/emptypb" 8 ) 9 10 type Subscribe struct { 11 gn.UnimplementedSubscribeServer 12 13 n *Nodes 14 } 15 16 func (f *Nodes) Subscribe() *Subscribe { 17 return &Subscribe{n: f} 18 } 19 20 func (s *Subscribe) Save(_ context.Context, l *gn.SaveLinkReq) (*emptypb.Empty, error) { 21 s.n.links.Save(l.GetLinks()) 22 return &emptypb.Empty{}, s.n.db.Save() 23 } 24 25 func (s *Subscribe) Remove(_ context.Context, l *gn.LinkReq) (*emptypb.Empty, error) { 26 s.n.links.Delete(l.GetNames()) 27 return &emptypb.Empty{}, s.n.db.Save() 28 } 29 30 func (s *Subscribe) Update(_ context.Context, req *gn.LinkReq) (*emptypb.Empty, error) { 31 s.n.links.Update(req.Names) 32 return &emptypb.Empty{}, s.n.db.Save() 33 } 34 35 func (s *Subscribe) Get(context.Context, *emptypb.Empty) (*gn.GetLinksResp, error) { 36 return &gn.GetLinksResp{Links: s.n.links.Links()}, nil 37 }