go
24 lines · 1 tab
Leah Thompson
Jan 2026
1 tab
package api
import (
"net/http"
"runtime/debug"
)
var (
Version = "dev"
Commit = "unknown"
)
func VersionHandler(w http.ResponseWriter, _ *http.Request) {
info, _ := debug.ReadBuildInfo()
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
_, _ = w.Write([]byte("version=" + Version + "
"))
_, _ = w.Write([]byte("commit=" + Commit + "
"))
if info != nil {
_, _ = w.Write([]byte("go=" + info.GoVersion + "
"))
}
}
1 file · go
Explain with highlit
When you’re on call, you eventually ask: “what version is running?” I expose a tiny /version endpoint that returns build metadata derived from debug.ReadBuildInfo plus a few variables set at build time. The goal isn’t perfect SBOMs; it’s fast debugging: you can confirm commit SHA, module versions, and Go version without SSHing into anything. I like to include this info in logs at startup too, but the endpoint is useful for automation and for health-check dashboards. The key is to keep it non-sensitive: don’t include secrets or internal URLs. In production, I usually guard it behind internal auth or only expose it on an admin listener. This is a low-effort, high-value observability feature.
Related snips
go
package dbutil
import (
"context"
"github.com/jackc/pgconn"
Retry Postgres serialization failures with bounded attempts
go
postgres
transactions
by Leah Thompson
1 tab
rust
use tracing::{info, instrument};
#[instrument]
fn process_request(user_id: u64) {
info!(user_id, "Processing request");
// Work happens here
tracing for structured logging and distributed tracing
rust
observability
tracing
by Marcus Chen
1 tab
go
package files
import (
"context"
"time"
Presigned S3 upload URLs (AWS SDK v2)
go
aws
s3
by Leah Thompson
1 tab
go
package deps
import (
"net"
"net/http"
"time"
HTTP client tuned for production: timeouts, transport, and connection reuse
go
http
client
by Leah Thompson
1 tab
yaml
# Grafana provisioning: datasources
# /etc/grafana/provisioning/datasources/prometheus.yml
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
Grafana dashboards as code with JSON provisioning
grafana
dashboards
monitoring
by Ryan Nakamura
2 tabs
typescript
import React from "react";
type FallbackProps = {
error: Error;
reset: () => void;
};
React Error Boundary + error reporting hook
react
frontend
error-boundary
by codesnips
3 tabs
Share this code
Here's the card — post it anywhere.