installed gin
This commit is contained in:
@@ -3,21 +3,26 @@ package wix
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"ruben/inventory2/internal/domains/raw_events"
|
||||
"ruben/inventory2/internal/logging"
|
||||
"ruben/inventory2/internal/server/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func NewWebhookHandler(logger *logging.Logger, db *raw_events.Store) http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
func Webhooks(
|
||||
r *gin.RouterGroup,
|
||||
logger *logging.Logger,
|
||||
db *raw_events.Store,
|
||||
) {
|
||||
r.POST("/test", response.Handler(func(c *gin.Context) (response.Response, error) {
|
||||
r := c.Request
|
||||
|
||||
mux.HandleFunc("POST /test", func(w http.ResponseWriter, r *http.Request) {
|
||||
var body json.RawMessage
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
http.Error(w, "Failed to decode body as json: "+err.Error(), 500)
|
||||
return
|
||||
return nil, fmt.Errorf("failed to decode body as json: %w", err)
|
||||
}
|
||||
|
||||
ts := time.Now().UTC()
|
||||
@@ -30,12 +35,9 @@ func NewWebhookHandler(logger *logging.Logger, db *raw_events.Store) http.Handle
|
||||
Payload: body,
|
||||
})
|
||||
if err != nil {
|
||||
http.Error(w, "Error occurred saving the body as the event payload: "+err.Error(), 500)
|
||||
return
|
||||
return nil, fmt.Errorf("error occurred saving the body as the event payload: %w", err)
|
||||
}
|
||||
|
||||
w.WriteHeader(201)
|
||||
})
|
||||
|
||||
return mux
|
||||
return response.Status(201), nil
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user