mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
add the concept of Id to a module
This commit is contained in:
@@ -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())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user