42 lines
666 B
Go
42 lines
666 B
Go
|
package api
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
"th7/data/core"
|
||
|
"th7/ports"
|
||
|
"time"
|
||
|
|
||
|
"encoding/json"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
CheckChannelDur = time.Millisecond * 700
|
||
|
StartupSleepDur = time.Second * 5
|
||
|
)
|
||
|
|
||
|
type ChannelsWrapper struct {
|
||
|
Channels []core.Channel `json:"channels"`
|
||
|
}
|
||
|
|
||
|
func startService(man *Manager, core ports.CorePort) {
|
||
|
|
||
|
var chwrap ChannelsWrapper
|
||
|
|
||
|
time.Sleep(StartupSleepDur)
|
||
|
|
||
|
for {
|
||
|
chwrap.Channels = core.GetChannels()
|
||
|
marshaled, err := json.Marshal(chwrap)
|
||
|
if err != nil {
|
||
|
log.Println("Error marshaling struct:", chwrap.Channels)
|
||
|
}
|
||
|
|
||
|
man.broadcast <- Message{
|
||
|
messageType: CHANNELS,
|
||
|
data: []byte(marshaled),
|
||
|
}
|
||
|
time.Sleep(CheckChannelDur)
|
||
|
}
|
||
|
|
||
|
}
|