move router to module New func

This commit is contained in:
Joel Wetzell
2025-12-06 23:00:45 -06:00
parent 8d8347fc4d
commit 9a06949b5b
16 changed files with 30 additions and 93 deletions

View File

@@ -23,7 +23,7 @@ type ResponseData struct {
func init() {
RegisterModule(ModuleRegistration{
Type: "net.http.server",
New: func(config config.ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig, router *Router) (Module, error) {
params := config.Params
port, ok := params["port"]
if !ok {
@@ -36,7 +36,7 @@ func init() {
return nil, fmt.Errorf("net.http.server port must be uint16")
}
return &HTTPServer{Port: uint16(portNum), config: config}, nil
return &HTTPServer{Port: uint16(portNum), config: config, router: router}, nil
},
})
}
@@ -49,10 +49,6 @@ func (hs *HTTPServer) Type() string {
return hs.config.Type
}
func (hs *HTTPServer) RegisterRouter(router *Router) {
hs.router = router
}
func (hs *HTTPServer) HandleDefault(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")