add the concept of Id to a module

This commit is contained in:
Joel Wetzell
2025-11-18 19:13:14 -06:00
parent b3735ee713
commit 9ad60c8193
5 changed files with 61 additions and 18 deletions

View File

@@ -8,13 +8,15 @@ import (
)
type TCPServer struct {
Port uint16
config ModuleConfig
Port uint16
}
func init() {
RegisterModule(ModuleRegistration{
Type: "net.tcp.server",
New: func(params map[string]any) (Module, error) {
New: func(config ModuleConfig) (Module, error) {
params := config.Params
port, ok := params["port"]
if !ok {
return nil, fmt.Errorf("tcp server requires a port parameter")
@@ -26,11 +28,19 @@ func init() {
return nil, fmt.Errorf("tcp server port must be uint16")
}
return TCPServer{Port: uint16(portNum)}, nil
return TCPServer{Port: uint16(portNum), config: config}, nil
},
})
}
func (ts TCPServer) Id() string {
return ts.config.Id
}
func (ts TCPServer) Type() string {
return ts.config.Type
}
func (ts TCPServer) HandleClient(ctx context.Context, client net.Conn) {
slog.Info("handling connection", "remoteAddr", client.RemoteAddr().String())