chore: make callbacks return same struct as /api/rawdata
This commit is contained in:
parent
78c27a261b
commit
a428f37e02
2 changed files with 42 additions and 33 deletions
|
|
@ -6,7 +6,9 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/traefik/traefik/v3/pkg/api"
|
||||
"github.com/traefik/traefik/v3/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v3/pkg/config/runtime"
|
||||
"github.com/traefik/traefik/v3/pkg/config/static"
|
||||
"github.com/traefik/traefik/v3/pkg/safe"
|
||||
)
|
||||
|
|
@ -24,23 +26,23 @@ func New(config *static.Configuration) *Updater {
|
|||
}
|
||||
|
||||
func (u *Updater) HandleConfigUpdate(cfg dynamic.Configuration) {
|
||||
body, err := json.Marshal(cfg)
|
||||
runtimeConfig := runtime.NewConfig(cfg)
|
||||
|
||||
if err != nil {
|
||||
// should never happen?
|
||||
body := bytes.NewBuffer([]byte{})
|
||||
result := api.GetRunTimeRepresentation(runtimeConfig)
|
||||
|
||||
if err := json.NewEncoder(body).Encode(result); err != nil {
|
||||
log.Error().Err(err).Msg("Error while marshalling dynamic configuration data to json")
|
||||
return
|
||||
}
|
||||
|
||||
requestBody := bytes.NewBuffer(body)
|
||||
|
||||
for _, url := range u.callbackUrls {
|
||||
safe.Go(func() {
|
||||
resp, err := http.Post(url, "application/json", requestBody)
|
||||
resp, err := http.Post(url, "application/json", body)
|
||||
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("url", url).Msg("Error while sending configuration data to callback")
|
||||
} else {
|
||||
} else {
|
||||
log.Debug().Str("url", url).Msg("Configuration data sent")
|
||||
resp.Body.Close()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue