Files
showbridge-go/internal/processing/http-response-encode.go
2025-11-22 17:59:28 -06:00

42 lines
795 B
Go

package processing
import (
"context"
"fmt"
"io"
"net/http"
)
type HTTPResponseEncode struct {
config ProcessorConfig
}
func (hre *HTTPResponseEncode) Process(ctx context.Context, payload any) (any, error) {
payloadResponse, ok := payload.(*http.Response)
if !ok {
return nil, fmt.Errorf("http.response.encode processor only accepts an http.Response")
}
defer payloadResponse.Body.Close()
bytes, err := io.ReadAll(payloadResponse.Body)
if err != nil {
return nil, err
}
return bytes, nil
}
func (hre *HTTPResponseEncode) Type() string {
return hre.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "http.response.encode",
New: func(config ProcessorConfig) (Processor, error) {
return &HTTPResponseEncode{config: config}, nil
},
})
}