diff --git a/internal/framer/framer.go b/internal/framer/framer.go index 4bb36d0..39b9453 100644 --- a/internal/framer/framer.go +++ b/internal/framer/framer.go @@ -1,9 +1,5 @@ package framer -import ( - "fmt" -) - type Framer interface { Decode([]byte) [][]byte Encode([]byte) []byte @@ -11,19 +7,19 @@ type Framer interface { Buffer() []byte } -func GetFramer(framingType string) (Framer, error) { +func GetFramer(framingType string) Framer { switch framingType { case "CR": - return NewByteSeparatorFramer([]byte{'\r'}), nil + return NewByteSeparatorFramer([]byte{'\r'}) case "LF": - return NewByteSeparatorFramer([]byte{'\n'}), nil + return NewByteSeparatorFramer([]byte{'\n'}) case "CRLF": - return NewByteSeparatorFramer([]byte{'\r', '\n'}), nil + return NewByteSeparatorFramer([]byte{'\r', '\n'}) case "SLIP": - return NewSlipFramer(), nil + return NewSlipFramer() case "RAW": - return NewRawFramer(), nil + return NewRawFramer() default: - return nil, fmt.Errorf("unknown framing method: %s", framingType) + return nil } } diff --git a/internal/module/serial-client.go b/internal/module/serial-client.go index dd4a0c8..2922f96 100644 --- a/internal/module/serial-client.go +++ b/internal/module/serial-client.go @@ -56,10 +56,10 @@ func init() { framingMethod = framingMethodString } - framer, err := framer.GetFramer(framingMethod) + framer := framer.GetFramer(framingMethod) - if err != nil { - return nil, err + if framer == nil { + return nil, fmt.Errorf("serial.client unknown framing method: %s", framingMethod) } buadRate, ok := params["baudRate"] diff --git a/internal/module/tcp-client.go b/internal/module/tcp-client.go index 7a2e4ba..5fd315d 100644 --- a/internal/module/tcp-client.go +++ b/internal/module/tcp-client.go @@ -64,15 +64,15 @@ func init() { framingMethodString, ok := framingMethodRaw.(string) if !ok { - return nil, errors.New("misc.serial.client framing method must be a string") + return nil, errors.New("net.tcp.client framing method must be a string") } framingMethod = framingMethodString } - framer, err := framer.GetFramer(framingMethod) + framer := framer.GetFramer(framingMethod) - if err != nil { - return nil, err + if framer == nil { + return nil, fmt.Errorf("net.tcp.client unknown framing method: %s", framingMethod) } return &TCPClient{framer: framer, Addr: addr, config: config, ctx: ctx, router: router, logger: slog.Default().With("component", "module", "id", config.Id)}, nil diff --git a/internal/module/tcp-server.go b/internal/module/tcp-server.go index 9227e2f..b9ce202 100644 --- a/internal/module/tcp-server.go +++ b/internal/module/tcp-server.go @@ -53,15 +53,15 @@ func init() { framingMethodString, ok := framingMethodRaw.(string) if !ok { - return nil, errors.New("misc.serial.client framing method must be a string") + return nil, errors.New("net.tcp.server framing method must be a string") } framingMethod = framingMethodString } - framer, err := framer.GetFramer(framingMethod) + framer := framer.GetFramer(framingMethod) - if err != nil { - return nil, err + if framer == nil { + return nil, fmt.Errorf("net.tcp.server unknown framing method: %s", framingMethod) } ipString := "0.0.0.0"