Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions internal/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"net/http"
"runtime"
"sync/atomic"
"time"

"github.com/moabdelazem/gitops-sample-app/internal/config"
Expand All @@ -16,9 +17,10 @@ import (
)

type Handler struct {
cfg *config.Config
tmpl *template.Template
startTime time.Time
cfg *config.Config
tmpl *template.Template
startTime time.Time
requestCount atomic.Int64
}

func New(cfg *config.Config, tmpl *template.Template) *Handler {
Expand All @@ -36,6 +38,7 @@ func (h *Handler) Register(mux *http.ServeMux) {
}

func (h *Handler) Index(w http.ResponseWriter, r *http.Request) {
h.requestCount.Add(1)
info := h.buildInfo()
w.Header().Set("Content-Type", "text/html; charset=utf-8")
if err := h.tmpl.Execute(w, info); err != nil {
Expand All @@ -58,15 +61,16 @@ func (h *Handler) APIInfo(w http.ResponseWriter, r *http.Request) {

func (h *Handler) buildInfo() model.AppInfo {
return model.AppInfo{
Version: version.Version,
GitCommit: version.GitCommit,
BuildTime: version.BuildTime,
Environment: h.cfg.Environment,
PodName: h.cfg.PodName,
NodeName: h.cfg.NodeName,
HostIP: getHostIP(),
GoVersion: runtime.Version(),
Uptime: formatUptime(time.Since(h.startTime)),
Version: version.Version,
GitCommit: version.GitCommit,
BuildTime: version.BuildTime,
Environment: h.cfg.Environment,
PodName: h.cfg.PodName,
NodeName: h.cfg.NodeName,
HostIP: getHostIP(),
GoVersion: runtime.Version(),
Uptime: formatUptime(time.Since(h.startTime)),
RequestCount: h.requestCount.Load(),
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/model/appinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ type AppInfo struct {
HostIP string `json:"host_ip"`
GoVersion string `json:"go_version"`
Uptime string `json:"uptime"`
RequestCount int64 `json:"request_count"`
}
315 changes: 166 additions & 149 deletions web/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,160 +1,177 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="GitOps Sample App - deployment metadata dashboard">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="GitOps Sample App - deployment metadata dashboard"
/>
<title>GitOps Sample App</title>
<meta http-equiv="refresh" content="30">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<meta http-equiv="refresh" content="30" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap"
rel="stylesheet"
/>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
font-family: "Inter", sans-serif;
background: #111;
color: #e5e5e5;
min-height: 100vh;
display: flex;
justify-content: center;
padding: 4rem 1.5rem;
}

.container {
max-width: 640px;
width: 100%;
}

h1 {
font-size: 1.25rem;
font-weight: 600;
color: #fff;
margin-bottom: 0.25rem;
}

.subtitle {
font-size: 0.8rem;
color: #666;
margin-bottom: 2rem;
}

.env-badge {
display: inline-block;
padding: 0.2rem 0.6rem;
border-radius: 4px;
font-size: 0.65rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.05em;
margin-bottom: 2rem;
}

.env-badge--development {
background: #1e3a5f;
color: #7db8f0;
}

.env-badge--staging {
background: #3d3214;
color: #d4a841;
}

.env-badge--production,
.env-badge--prod {
background: #1a3a2a;
color: #4ade80;
}

table {
width: 100%;
border-collapse: collapse;
}

tr {
border-bottom: 1px solid #222;
}

td {
padding: 0.75rem 0;
vertical-align: top;
}

td:first-child {
font-size: 0.75rem;
font-weight: 500;
color: #666;
text-transform: uppercase;
letter-spacing: 0.05em;
width: 140px;
white-space: nowrap;
}

td:last-child {
font-family: "JetBrains Mono", monospace;
font-size: 0.85rem;
color: #e5e5e5;
word-break: break-all;
}

.footer {
margin-top: 2rem;
padding-top: 1rem;
border-top: 1px solid #222;
font-size: 0.7rem;
color: #444;
}

@media (max-width: 480px) {
body {
font-family: 'Inter', sans-serif;
background: #111;
color: #e5e5e5;
min-height: 100vh;
display: flex;
justify-content: center;
padding: 4rem 1.5rem;
}

.container {
max-width: 640px;
width: 100%;
}

h1 {
font-size: 1.25rem;
font-weight: 600;
color: #fff;
margin-bottom: 0.25rem;
}

.subtitle {
font-size: 0.8rem;
color: #666;
margin-bottom: 2rem;
padding: 2rem 1rem;
}

.env-badge {
display: inline-block;
padding: 0.2rem 0.6rem;
border-radius: 4px;
font-size: 0.65rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.05em;
margin-bottom: 2rem;
}

.env-badge--development {
background: #1e3a5f;
color: #7db8f0;
}

.env-badge--staging {
background: #3d3214;
color: #d4a841;
}

.env-badge--production, .env-badge--prod {
background: #1a3a2a;
color: #4ade80;
}

table {
width: 100%;
border-collapse: collapse;
}

tr {
border-bottom: 1px solid #222;
}

td {
padding: 0.75rem 0;
vertical-align: top;
}

td:first-child {
font-size: 0.75rem;
font-weight: 500;
color: #666;
text-transform: uppercase;
letter-spacing: 0.05em;
width: 140px;
white-space: nowrap;
}

td:last-child {
font-family: 'JetBrains Mono', monospace;
font-size: 0.85rem;
color: #e5e5e5;
word-break: break-all;
}

.footer {
margin-top: 2rem;
padding-top: 1rem;
border-top: 1px solid #222;
font-size: 0.7rem;
color: #444;
}

@media (max-width: 480px) {
body { padding: 2rem 1rem; }
td:first-child { width: 100px; }
width: 100px;
}
}
</style>
</head>
<body>
</head>
<body>
<div class="container">
<h1>GitOps Sample App</h1>
<p class="subtitle">Deployment Metadata</p>
<span class="env-badge env-badge--{{.Environment}}">{{.Environment}}</span>

<table>
<tr>
<td>Version</td>
<td>{{.Version}}</td>
</tr>
<tr>
<td>Commit</td>
<td>{{.GitCommit}}</td>
</tr>
<tr>
<td>Built</td>
<td>{{.BuildTime}}</td>
</tr>
<tr>
<td>Environment</td>
<td>{{.Environment}}</td>
</tr>
<tr>
<td>Pod</td>
<td>{{.PodName}}</td>
</tr>
<tr>
<td>Node</td>
<td>{{.NodeName}}</td>
</tr>
<tr>
<td>Host IP</td>
<td>{{.HostIP}}</td>
</tr>
</table>

<div class="footer">
Uptime: {{.Uptime}} / Go {{.GoVersion}} / Auto-refreshes every 30s
</div>
<h1>GitOps Sample App</h1>
<p class="subtitle">Deployment Metadata</p>
<span class="env-badge env-badge--{{.Environment}}"
>{{.Environment}}</span
>

<table>
<tr>
<td>Version</td>
<td>{{.Version}}</td>
</tr>
<tr>
<td>Commit</td>
<td>{{.GitCommit}}</td>
</tr>
<tr>
<td>Built</td>
<td>{{.BuildTime}}</td>
</tr>
<tr>
<td>Environment</td>
<td>{{.Environment}}</td>
</tr>
<tr>
<td>Pod</td>
<td>{{.PodName}}</td>
</tr>
<tr>
<td>Node</td>
<td>{{.NodeName}}</td>
</tr>
<tr>
<td>Host IP</td>
<td>{{.HostIP}}</td>
</tr>
<tr>
<td>Requests</td>
<td>{{.RequestCount}}</td>
</tr>
</table>

<div class="footer">
Uptime: {{.Uptime}} / Go {{.GoVersion}} / Auto-refreshes every 30s
</div>
</div>
</body>
</body>
</html>