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:
@@ -9,13 +9,15 @@ import (
|
||||
)
|
||||
|
||||
type UDPServer struct {
|
||||
Port uint16
|
||||
Port uint16
|
||||
config ModuleConfig
|
||||
}
|
||||
|
||||
func init() {
|
||||
RegisterModule(ModuleRegistration{
|
||||
Type: "net.udp.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("udp server requires a port parameter")
|
||||
@@ -27,11 +29,19 @@ func init() {
|
||||
return nil, fmt.Errorf("udp server port must be uint16")
|
||||
}
|
||||
|
||||
return UDPServer{Port: uint16(portNum)}, nil
|
||||
return UDPServer{Port: uint16(portNum), config: config}, nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (us UDPServer) Id() string {
|
||||
return us.config.Id
|
||||
}
|
||||
|
||||
func (us UDPServer) Type() string {
|
||||
return us.config.Id
|
||||
}
|
||||
|
||||
func (us UDPServer) Run(ctx context.Context) error {
|
||||
|
||||
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf(":%d", us.Port))
|
||||
|
||||
Reference in New Issue
Block a user