修复内存数据更新

This commit is contained in:
奶爸 2019-12-13 17:56:14 +08:00
parent a8e02fc9bb
commit af146872fe
3 changed files with 8 additions and 4 deletions

2
go.mod
View File

@ -22,5 +22,7 @@ require (
github.com/spf13/viper v1.6.1
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 // indirect
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 // indirect
google.golang.org/grpc v1.25.1
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect
)

View File

@ -10,8 +10,8 @@ type Server struct {
Name string
Secret string
Host Host
State State
Host *Host
State *State
Stream pb.NezhaService_HeartbeatServer `gorm:"-" json:"-"`
StreamClose chan<- error `gorm:"-" json:"-"`

View File

@ -21,9 +21,10 @@ func (s *NezhaHandler) ReportState(c context.Context, r *pb.State) (*pb.Receipt,
if clientID, err = s.Auth.Check(c); err != nil {
return nil, err
}
state := model.PB2State(r)
dao.ServerLock.RLock()
defer dao.ServerLock.RUnlock()
dao.ServerList[clientID].State = model.PB2State(r)
dao.ServerList[clientID].State = &state
return &pb.Receipt{Proced: true}, nil
}
@ -61,8 +62,9 @@ func (s *NezhaHandler) Register(c context.Context, r *pb.Host) (*pb.Receipt, err
if clientID, err = s.Auth.Check(c); err != nil {
return nil, err
}
host := model.PB2Host(r)
dao.ServerLock.RLock()
defer dao.ServerLock.RUnlock()
dao.ServerList[clientID].Host = model.PB2Host(r)
dao.ServerList[clientID].Host = &host
return &pb.Receipt{Proced: true}, nil
}