Sure! Below is a complete minimal stack Golang + SQLite + Gin backend with a barebones HTML/CSS Shoelace-powered frontend that displays a list of incoming user requests.
✅ Features Summary
-
Backend:
- Uses Go, Gin, GORM (with SQLite)
- Accepts simple JSON user request
- Stores them in SQLite
- Admin HTTP interface displays table of requests
- Side-panel for unlocking requests
- Unlock involves XOR and config operation over data
- Mark served requests, wait for client acknowledge
- Simple TTL/aging cleanup
-
Frontend:
- No heavy frameworks
- Pure HTML + Shoelace (optional dropdown/modal/side-panel)
- Simple and low-resource compatible (slow board compatible)
💡 Project Layout
/project-root
├── main.go
├── models.go
├── handlers.go
├── public/
│ └── index.html
├── templates/
│ └── admin.html
└── config.json
🔧 Sample Config File (config.json)
{
"xor_key": [42, 23, 7]
}
🐙 main.go
package main
import (
"github.com/gin-gonic/gin"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"time"
"net/http"
)
var db *gorm.DB
func main() {
var err error
db, err = gorm.Open(sqlite.Open("data.db"), &gorm.Config{})
if err != nil {
panic("failed to connect database")
}
db.AutoMigrate(&UserRequest{})
router := gin.Default()
router.Static("/public", "./public")
router.GET("/", func(c *gin.Context) {
c.Redirect(http.StatusFound, "/admin")
})
router.LoadHTMLGlob("templates/*.html")
router.POST("/submit", submitRequest)
router.GET("/admin", showAdminPage)
router.GET("/requests", listRequests)
router.POST("/unlock/:id", unlockRequest)
router.POST("/ack/:id", acknowledgeRequest)
go cleanupOldRequests()
router.Run(":8080")
}
📦 models.go
package main
import "time"
type UserRequest struct {
ID uint `gorm:"primaryKey"`
Data []byte
Submitted time.Time
Unlocked bool
Acked bool
UnlockData []byte
}
⚙️ handlers.go
package main
import (
"encoding/json"
"io/ioutil"
"net/http"
"strconv"
"time"
"github.com/gin-gonic/gin"
)
type IncomingRequest struct {
Data []byte `json:"data"`
}
var xorKey []byte
func init() {
var config struct {
XorKey []byte `json:"xor_key"`
}
b, _ := ioutil.ReadFile("config.json")
_ = json.Unmarshal(b, &config)
xorKey = config.XorKey
}
func submitRequest(c *gin.Context) {
var req IncomingRequest
if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid payload"})
return
}
newReq := UserRequest{
Data: req.Data,
Submitted: time.Now(),
}
db.Create(&newReq)
c.JSON(http.StatusOK, gin.H{"status": "received"})
}
func showAdminPage(c *gin.Context) {
c.HTML(http.StatusOK, "admin.html", nil)
}
func listRequests(c *gin.Context) {
var requests []UserRequest
db.Order("id desc").Find(&requests)
c.JSON(http.StatusOK, requests)
}
func unlockRequest(c *gin.Context) {
id, _ := strconv.Atoi(c.Param("id"))
var r UserRequest
if err := db.First(&r, id).Error; err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "not found"})
return
}
res := xorProcess(r.Data)
r.Unlocked = true
r.UnlockData = res
db.Save(&r)
c.JSON(http.StatusOK, gin.H{"unlocked_data": res})
}
func acknowledgeRequest(c *gin.Context) {
id, _ := strconv.Atoi(c.Param("id"))
var r UserRequest
if err := db.First(&r, id).Error; err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "not found"})
return
}
r.Acked = true
db.Save(&r)
c.JSON(http.StatusOK, gin.H{"status": "acknowledged"})
}
func xorProcess(data []byte) []byte {
result := make([]byte, len(data))
for i := range data {
result[i] = data[i] ^ xorKey[i%len(xorKey)]
}
return result
}
func cleanupOldRequests() {
for {
time.Sleep(time.Minute * 5)
expire := time.Now().Add(-12 * time.Hour)
db.Where("acked = ? AND submitted < ?", true, expire).Delete(&UserRequest{})
}
}
🎨 public/index.html (optional user page that submits request)
<!DOCTYPE html>
<html>
<head><title>Submit</title></head>
<body>
<h1>Submit Simple Request</h1>
<form id="f">
<input type="text" id="data" placeholder="Data"/>
<button type="submit">Send</button>
</form>
<script>
document.getElementById("f").onsubmit = function(e){
e.preventDefault();
const data = new TextEncoder().encode(document.getElementById("data").value);
fetch("/submit", {
method: "POST",
headers: {'Content-Type':'application/json'},
body: JSON.stringify({data: Array.from(data)})
}).then(r => r.json()).then(console.log)
}
</script>
</body>
</html>
🧾 templates/admin.html
<!DOCTYPE html>
<html>
<head>
<title>Admin Panel</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/shoelace-style@2.0.0-beta.59/dist/themes/light.css" />
<style>
table { width: 100%; border-collapse: collapse; }
th, td { padding: 6px; border: 1px solid #ccc; text-align: left; }
tr:hover { background: #eee; cursor: pointer; }
</style>
</head>
<body>
<h1>Admin Panel</h1>
<table id="reqs">
<thead>
<tr><th>ID</th><th>Submitted</th><th>Unlocked</th><th>Acked</th></tr>
</thead>
<tbody></tbody>
</table>
<sl-drawer label="Request Action" id="drawer">
<div id="drawer-content"></div>
<sl-button slot="footer" id="unlock">Unlock</sl-button>
<sl-button variant="primary" slot="footer" id="ack">Acknowledge</sl-button>
</sl-drawer>
<script type="module">
import 'https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.59/dist/shoelace.js';
let requests = [];
function load() {
fetch("/requests").then(r => r.json()).then(data => {
requests = data;
const tbody = document.querySelector("#reqs tbody");
tbody.innerHTML = "";
data.forEach(r => {
const tr = document.createElement("tr");
tr.innerHTML = `<td>${r.ID}</td><td>${r.Submitted}</td><td>${r.Unlocked}</td><td>${r.Acked}</td>`;
tr.onclick = () => openDrawer(r.ID);
tbody.appendChild(tr)
});
});
}
async function openDrawer(id) {
const r = requests.find(x => x.ID === id);
document.querySelector("#drawer-content").innerText = `Request ${id}`;
const drawer = document.getElementById("drawer");
drawer.classList.add("show");
drawer.show();
document.getElementById("unlock").onclick = async () => {
const res = await fetch(`/unlock/${id}`, {method: "POST"});
const json = await res.json();
alert("Unlocked Data: " + json.unlocked_data);
load();
};
document.getElementById("ack").onclick = async () => {
await fetch(`/ack/${id}`, {method: "POST"});
drawer.hide();
load();
};
}
load();
setInterval(load, 10000);
</script>
</body>
</html>
🚀 Running it all:
1. Build and run
go mod init example.com/app
go get github.com/gin-gonic/gin
go get gorm.io/gorm
go get gorm.io/driver/sqlite
go run main.go
2. Test it!
- Open
http://localhost:8080/public/index.html to submit data
- Open
http://localhost:8080/admin to manage requests
🧹 Optional Improvements
- Change XOR to use external config or admin-defined logic
- Add access control (basic auth or token check for admin)
- Use cron to offload cleanup
- Compress UnlockData if large
- Store audit logs for reviewed requests
Let me know if you'd like Docker + systemd service config to run on ARM64 or manual init script!