dashboard/services/uniss/httpserverhandle.go
2025-06-04 17:07:17 +08:00

40 lines
870 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package uniss
import (
"dashboard/models"
"dashboard/pkg/singlemap"
)
type httpServerHandler struct {
httpC chan *models.UnisHttpRequest
// mu sync.RWMutex // 没有必要使用锁应为完全可以保证在一个协程内访问map
*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) httpHandle(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 {
}
}
}