orama/invest-api/handler/helpers.go
anonpenguin23 655bd92178 Squashed 'website/' content from commit d19b985
git-subtree-dir: website
git-subtree-split: d19b98589ec5d235560a210b26195b653a65a808
2026-03-26 18:14:59 +02:00

29 lines
680 B
Go

package handler
import (
"database/sql"
"encoding/json"
"net/http"
)
func jsonResponse(w http.ResponseWriter, status int, data any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
json.NewEncoder(w).Encode(data)
}
func jsonError(w http.ResponseWriter, status int, msg string) {
jsonResponse(w, status, map[string]string{"error": msg})
}
func logActivity(database *sql.DB, eventType, wallet, detail string) {
truncated := wallet
if len(wallet) > 10 {
truncated = wallet[:6] + "..." + wallet[len(wallet)-4:]
}
database.Exec(
"INSERT INTO activity_log (event_type, wallet, detail) VALUES (?, ?, ?)",
eventType, truncated, detail,
)
}