mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 21:05:30 +00:00
add basic http server
This commit is contained in:
40
internal/processing/http-request-encode.go
Normal file
40
internal/processing/http-request-encode.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package processing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type HTTPRequestEncode struct {
|
||||
config ProcessorConfig
|
||||
}
|
||||
|
||||
func (hre *HTTPRequestEncode) Process(ctx context.Context, payload any) (any, error) {
|
||||
payloadRequest, ok := payload.(*http.Request)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("http.request.encode processor only accepts an OSCMessage")
|
||||
}
|
||||
|
||||
bytes, err := io.ReadAll(payloadRequest.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return bytes, nil
|
||||
}
|
||||
|
||||
func (hre *HTTPRequestEncode) Type() string {
|
||||
return hre.config.Type
|
||||
}
|
||||
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "http.request.encode",
|
||||
New: func(config ProcessorConfig) (Processor, error) {
|
||||
return &HTTPRequestEncode{config: config}, nil
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user