Refactor project structure: enhance tests, improve server shutdown, expand CI checks, and update UI for better event presentation.
This commit is contained in:
@@ -32,17 +32,6 @@ var (
|
||||
updates = make(map[string]DiunEvent)
|
||||
)
|
||||
|
||||
// Exported for test package
|
||||
func GetUpdatesMap() map[string]DiunEvent {
|
||||
return updates
|
||||
}
|
||||
|
||||
func UpdatesReset() {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
updates = make(map[string]DiunEvent)
|
||||
}
|
||||
|
||||
func UpdateEvent(event DiunEvent) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
@@ -60,10 +49,21 @@ func GetUpdates() map[string]DiunEvent {
|
||||
}
|
||||
|
||||
func WebhookHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
var event DiunEvent
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&event); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
log.Printf("WebhookHandler: failed to decode request: %v", err)
|
||||
http.Error(w, "bad request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if event.Image == "" {
|
||||
http.Error(w, "bad request: image field is required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user