Files
15-puzzle/internal/puzzle/handler.go
T
Ilia Denisov 31957206b8 initial
2025-09-03 18:43:28 +03:00

45 lines
1001 B
Go

package puzzle
import "15-puzzle/internal/model"
func (c *Controller) ApiResponseHandler(u model.ApiResponse) {
switch {
case u.Err != nil:
c.ApiErrorHandler(*u.Err)
case u.Info != nil:
c.ApiInfoHandler(*u.Info)
case u.Stats != nil:
c.ApiStatsHandler(*u.Stats)
case u.Monitoring != nil:
c.ApiMonitoringHandler(*u.Monitoring)
}
}
func (c *Controller) ApiInfoHandler(s model.Info) {
for _, h := range c.screens {
if i, ok := h.(interface{ ApiInfoHandler(model.Info) }); ok {
i.ApiInfoHandler(s)
}
}
}
func (c *Controller) ApiStatsHandler(s model.Stats) {
for _, h := range c.screens {
if i, ok := h.(interface{ ApiStatsHandler(model.Stats) }); ok {
i.ApiStatsHandler(s)
}
}
}
func (c *Controller) ApiMonitoringHandler(m model.Monitoring) {
for _, h := range c.screens {
if i, ok := h.(interface{ ApiMonitoringHandler(model.Monitoring) }); ok {
i.ApiMonitoringHandler(m)
}
}
}
func (c *Controller) ApiErrorHandler(e string) {
c.Debug("api error: %s", e)
}