fix: must use json marshal to convert to bytes, then unmarshal to a map

This commit is contained in:
Derrick Hammer 2024-02-11 23:23:32 -05:00
parent ae9b036cb5
commit e907aa7e99
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 13 additions and 3 deletions

View File

@ -6,7 +6,6 @@ import (
"encoding/json" "encoding/json"
"git.lumeweb.com/LumeWeb/gitea-github-proxy/config" "git.lumeweb.com/LumeWeb/gitea-github-proxy/config"
"git.lumeweb.com/LumeWeb/gitea-github-proxy/db/model" "git.lumeweb.com/LumeWeb/gitea-github-proxy/db/model"
"github.com/fatih/structs"
"go.uber.org/zap" "go.uber.org/zap"
"gorm.io/gorm" "gorm.io/gorm"
"io" "io"
@ -46,13 +45,24 @@ func (whm *WebhookManager) sendWebhooks(request interface{}, r *http.Request) {
for _, app := range apps { for _, app := range apps {
go func(app model.Apps) { go func(app model.Apps) {
rawMap := structs.New(request).Map() payloadBytes, err := json.Marshal(request)
if err != nil {
whm.logger.Error("Failed to marshal payload", zap.Error(err))
return
}
var rawMap map[string]interface{}
err = json.Unmarshal(payloadBytes, &rawMap)
if err != nil {
whm.logger.Error("Failed to unmarshal payload", zap.Error(err))
return
}
rawMap["installation"] = struct { rawMap["installation"] = struct {
ID uint `json:"id"` ID uint `json:"id"`
}{ID: app.ID} }{ID: app.ID}
payloadBytes, err := json.Marshal(rawMap) payloadBytes, err = json.Marshal(request)
if err != nil { if err != nil {
whm.logger.Error("Failed to marshal payload", zap.Error(err)) whm.logger.Error("Failed to marshal payload", zap.Error(err))
return return