nezha/service/dao/dao.go

57 lines
807 B
Go
Raw Normal View History

2019-12-08 03:59:58 -05:00
package dao
import (
2019-12-09 05:14:31 -05:00
"sync"
2019-12-08 03:59:58 -05:00
"github.com/patrickmn/go-cache"
"gorm.io/gorm"
2019-12-08 03:59:58 -05:00
2020-11-10 21:07:45 -05:00
"github.com/naiba/nezha/model"
pb "github.com/naiba/nezha/proto"
2019-12-08 03:59:58 -05:00
)
2020-12-19 23:18:27 -05:00
const (
SnapshotDelay = 3
ReportDelay = 2
)
2019-12-08 03:59:58 -05:00
// Conf ..
var Conf *model.Config
// Cache ..
var Cache *cache.Cache
// DB ..
var DB *gorm.DB
2019-12-09 05:14:31 -05:00
// ServerList ..
var ServerList map[string]*model.Server
// ServerLock ..
var ServerLock sync.RWMutex
2019-12-09 10:45:23 -05:00
// Version ..
var Version = "debug"
2019-12-10 04:57:57 -05:00
2020-10-28 23:20:32 -04:00
func init() {
if len(Version) > 7 {
Version = Version[:7]
}
}
2019-12-10 04:57:57 -05:00
// SendCommand ..
func SendCommand(cmd *pb.Command) {
ServerLock.RLock()
defer ServerLock.RUnlock()
var err error
for _, server := range ServerList {
if server.Stream != nil {
err = server.Stream.Send(cmd)
if err != nil {
close(server.StreamClose)
server.Stream = nil
}
}
}
}