cml04-falcon-system/injector/handlers/bundle.go

27 lines
734 B
Go
Raw Permalink Normal View History

2024-10-03 16:14:53 +02:00
package handlers
import (
"encoding/json"
"net/http"
"git.espin.casa/albert/cml04-falcon-system/internal/publisher"
"git.espin.casa/albert/cml04-falcon-system/internal/types"
"github.com/julienschmidt/httprouter"
)
func BundleHandler(publisher publisher.Publisher) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
// bundle holder
bundle := &types.BundleData{}
// decode bundle data
err := json.NewDecoder(r.Body).Decode(bundle)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
// publish event
if err := publisher.NewBundle(r.Context(), bundle); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}