Integration

Go backend integration.

Use this general server-side example as the starting point for jobs, articles, products, listings, events, announcements, or custom content.

Go

How this integration works

Use this in a Go backend package or internal integration module.

Keep your zedgad API key on the server. The integration sends a title, summary, public URL, optional image URL, and any useful metadata to the project webhook.

  • Place the file under internal/integrations or another server-side package.
  • Read ZEDGAD_API_KEY from the server environment.
  • Call SendContentToZedgad after your content model has a public URL.

Go

Create internal/integrations/zedgad.go

Replace the sample content fields with your own model fields. The important part is that zedgad receives a stable ID, content type, title, summary, public URL, optional image URL, and any metadata you want to keep with the post.

internal/integrations/zedgad.go
package integrations

import (
  "bytes"
  "encoding/json"
  "fmt"
  "net/http"
  "os"
  "time"
)

const zedgadWebhookURL = "https://api.zedgad.com/api/webhooks/content/"

func SendContentToZedgad(content Content) error {
  payload := map[string]any{
    "external_id": fmt.Sprint(content.ID),
    "type": content.Type,
    "title": content.Title,
    "summary": content.Summary,
    "url": content.PublicURL,
    "image_url": content.ImageURL,
    "metadata": map[string]any{
      "source": content.Source,
      "category": content.Category,
    },
  }

  body, err := json.Marshal(payload)
  if err != nil {
    return err
  }

  req, err := http.NewRequest("POST", zedgadWebhookURL, bytes.NewReader(body))
  if err != nil {
    return err
  }

  req.Header.Set("Authorization", "Bearer "+os.Getenv("ZEDGAD_API_KEY"))
  req.Header.Set("Content-Type", "application/json")

  client := &http.Client{Timeout: 20 * time.Second}
  res, err := client.Do(req)
  if err != nil {
    return err
  }
  defer res.Body.Close()

  if res.StatusCode >= 300 {
    return fmt.Errorf("zedgad request failed: %s", res.Status)
  }

  return nil
}