Initialize project with DIUN Webhook Dashboard: core Go app, Docker setup, static assets, and documentation.

This commit is contained in:
2026-02-23 16:47:50 +01:00
commit 2077d4132b
13 changed files with 290 additions and 0 deletions

68
main.go Normal file
View File

@@ -0,0 +1,68 @@
package main
import (
"encoding/json"
"log"
"net/http"
"sync"
"time"
)
type DiunEvent struct {
DiunVersion string `json:"diun_version"`
Hostname string `json:"hostname"`
Status string `json:"status"`
Provider string `json:"provider"`
Image string `json:"image"`
HubLink string `json:"hub_link"`
MimeType string `json:"mime_type"`
Digest string `json:"digest"`
Created time.Time `json:"created"`
Platform string `json:"platform"`
Metadata struct {
ContainerName string `json:"ctn_names"`
ContainerID string `json:"ctn_id"`
State string `json:"ctn_state"`
Status string `json:"ctn_status"`
} `json:"metadata"`
}
var (
mu sync.Mutex
updates = make(map[string]DiunEvent)
)
func webhookHandler(w http.ResponseWriter, r *http.Request) {
var event DiunEvent
if err := json.NewDecoder(r.Body).Decode(&event); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
mu.Lock()
// Use image as key (or container name if preferred)
updates[event.Image] = event
mu.Unlock()
log.Printf("Update received: %s (%s)", event.Image, event.Status)
w.WriteHeader(http.StatusOK)
}
func updatesHandler(w http.ResponseWriter, r *http.Request) {
mu.Lock()
defer mu.Unlock()
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(updates)
}
func main() {
http.HandleFunc("/webhook", webhookHandler)
http.HandleFunc("/api/updates", updatesHandler)
http.Handle("/", http.FileServer(http.Dir("./static")))
log.Println("Listening on :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}