diff --git a/go.mod b/go.mod index 912e532..a3855a4 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/model/server.go b/model/server.go index af9eb2e..d7db0dc 100644 --- a/model/server.go +++ b/model/server.go @@ -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:"-"` diff --git a/service/rpc/nezha.go b/service/rpc/nezha.go index e650353..3fc3222 100644 --- a/service/rpc/nezha.go +++ b/service/rpc/nezha.go @@ -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 }