mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 21:35:30 +00:00
42 lines
807 B
Go
42 lines
807 B
Go
package processor
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"github.com/jwetzell/showbridge-go/internal/config"
|
|
)
|
|
|
|
type IntParse struct {
|
|
config config.ProcessorConfig
|
|
}
|
|
|
|
func (ip *IntParse) Process(ctx context.Context, payload any) (any, error) {
|
|
payloadString, ok := payload.(string)
|
|
|
|
if !ok {
|
|
return nil, fmt.Errorf("int.parse processor only accepts a string")
|
|
}
|
|
|
|
// TODO(jwetzell): make base and bitSize configurable
|
|
payloadInt, err := strconv.ParseInt(payloadString, 10, 64)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return payloadInt, nil
|
|
}
|
|
|
|
func (ip *IntParse) Type() string {
|
|
return ip.config.Type
|
|
}
|
|
|
|
func init() {
|
|
RegisterProcessor(ProcessorRegistration{
|
|
Type: "int.parse",
|
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
|
return &IntParse{config: config}, nil
|
|
},
|
|
})
|
|
}
|