dashboard/services/uniss/httpserverhandle.go

39 lines
774 B
Go

package uniss
import (
"dashboard/models"
"dashboard/pkg/singlemap"
)
type httpServerHandler struct {
httpC chan *models.UnisHttpRequest
*singlemap.SingleMap[string,httpServerHandlerFunc]
}
type httpServerHandlerFunc func(*models.UnisHttpRequest, *models.UnisHttpResponse) error
func newhttpServerHandler() *httpServerHandler {
res := new(httpServerHandler)
res.httpC = make(chan *models.UnisHttpRequest)
res.SingleMap = singlemap.NewSingleMap[string,httpServerHandlerFunc]()
return res
}
func (u *httpServerHandler) httpServerHandle(msg *models.UnisHttpRequest) {
resP := msg.ResP
resC := msg.ResC
defer func() {
if resC != nil {
resC <- resP
}
}()
if fn, ok := u.Get(msg.Id); ok && fn != nil {
if err := fn(msg, resP); err == nil {
}
}
}