Files
showbridge-go/internal/processing/int-parse.go
2025-12-01 20:31:56 -06:00

40 lines
740 B
Go

package processing
import (
"context"
"fmt"
"strconv"
)
type IntParse struct {
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 ProcessorConfig) (Processor, error) {
return &IntParse{config: config}, nil
},
})
}