mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-11 10:10:46 +08:00
29 lines
633 B
Go
29 lines
633 B
Go
package serverctl
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gravitl/netmaker/models"
|
|
)
|
|
|
|
// ServerQueue - holds data to be updated across the server
|
|
var ServerQueue chan models.ServerUpdateData
|
|
|
|
func init() {
|
|
ServerQueue = make(chan models.ServerUpdateData, 100)
|
|
}
|
|
|
|
// Push - Pushes ServerUpdateData to be used later
|
|
func Push(serverData models.ServerUpdateData) {
|
|
ServerQueue <- serverData
|
|
}
|
|
|
|
// Pop - fetches first available data from queue
|
|
func Pop() (models.ServerUpdateData, error) {
|
|
select {
|
|
case serverData := <-ServerQueue:
|
|
return serverData, nil
|
|
default:
|
|
return models.ServerUpdateData{}, fmt.Errorf("empty server queue")
|
|
}
|
|
}
|