nezha/service/dao/dao.go

49 lines
746 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/jinzhu/gorm"
"github.com/patrickmn/go-cache"
"github.com/p14yground/nezha/model"
2019-12-10 04:57:57 -05:00
pb "github.com/p14yground/nezha/proto"
2019-12-08 03:59:58 -05:00
)
// Conf ..
var Conf *model.Config
// Cache ..
var Cache *cache.Cache
// DB ..
var DB *gorm.DB
// Admin ..
var Admin *model.User
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
// 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
}
}
}
}