netmaker/serverctl/serverq.go

37 lines
846 B
Go
Raw Normal View History

2022-01-14 23:33:14 +08:00
package serverctl
import (
"fmt"
"github.com/gravitl/netmaker/models"
)
// ServerQueue - holds data to be updated across the server
var ServerQueue chan ServerUpdateData
func init() {
ServerQueue = make(chan ServerUpdateData, 100)
}
// ServerUpdateData - contains data to configure server
// and if it should set peers
type ServerUpdateData struct {
2022-01-18 03:20:52 +08:00
UpdatePeers bool `json:"updatepeers" bson:"updatepeers"`
2022-01-14 23:33:14 +08:00
ServerNode models.Node `json:"servernode" bson:"servernode"`
}
// Push - Pushes ServerUpdateData to be used later
func Push(serverData ServerUpdateData) {
ServerQueue <- serverData
}
// Pop - fetches first available data from queue
func Pop() (ServerUpdateData, error) {
select {
case serverData := <-ServerQueue:
return serverData, nil
default:
return ServerUpdateData{}, fmt.Errorf("empty server queue")
}
}