aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2020-05-21 18:37:50 -0400
committerChristine Dodrill <me@christine.website>2020-05-21 18:37:50 -0400
commit77db7e371bc71fb671d38fa3b09cc4ec9e8657b6 (patch)
tree9aa10dd8598b61f2a5cb0bffe368ff6660816828
parent60b7fc345efd4a7a51d65cf555aa5cac454811d2 (diff)
downloadxesite-77db7e371bc71fb671d38fa3b09cc4ec9e8657b6.tar.xz
xesite-77db7e371bc71fb671d38fa3b09cc4ec9e8657b6.zip
cmd/site: more clacks
-rw-r--r--cmd/site/clacks.go25
-rw-r--r--cmd/site/main.go14
-rw-r--r--shell.nix2
3 files changed, 39 insertions, 2 deletions
diff --git a/cmd/site/clacks.go b/cmd/site/clacks.go
new file mode 100644
index 0000000..3415d14
--- /dev/null
+++ b/cmd/site/clacks.go
@@ -0,0 +1,25 @@
+package main
+
+import (
+ "math/rand"
+ "net/http"
+ "time"
+)
+
+type ClackSet []string
+
+func (cs ClackSet) Name() string {
+ return "GNU " + cs[rand.Intn(len(cs))]
+}
+
+func (cs ClackSet) Middleware(next http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Add("X-Clacks-Overhead", cs.Name())
+
+ next.ServeHTTP(w, r)
+ })
+}
+
+func init() {
+ rand.Seed(time.Now().Unix())
+}
diff --git a/cmd/site/main.go b/cmd/site/main.go
index bb7b369..b5f7df9 100644
--- a/cmd/site/main.go
+++ b/cmd/site/main.go
@@ -7,6 +7,7 @@ import (
"net/http"
"os"
"sort"
+ "strings"
"time"
"christine.website/cmd/site/internal/blog"
@@ -63,6 +64,7 @@ type Site struct {
Series []string
SignalBoost []Person
+ clacks ClackSet
patrons []string
rssFeed *feeds.Feed
jsonFeed *jsonfeed.Feed
@@ -73,6 +75,14 @@ type Site struct {
var gitRev = os.Getenv("GIT_REV")
+func envOr(key, or string) string {
+ if result, ok := os.LookupEnv(key); ok {
+ return result
+ }
+
+ return or
+}
+
func (s *Site) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := opname.With(r.Context(), "site.ServeHTTP")
ctx = ln.WithF(ctx, ln.F{
@@ -82,9 +92,8 @@ func (s *Site) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if gitRev != "" {
w.Header().Add("X-Git-Rev", gitRev)
}
- w.Header().Add("X-Clacks-Overhead", "GNU Ashlynn")
- middleware.RequestID(s.xffmw.Handler(ex.HTTPLog(s.mux))).ServeHTTP(w, r)
+ s.clacks.Middleware(middleware.RequestID(s.xffmw.Handler(ex.HTTPLog(s.mux)))).ServeHTTP(w, r)
}
var arbDate = time.Date(2020, time.February, 29, 0, 0, 0, 0, time.UTC)
@@ -168,6 +177,7 @@ func Build() (*Site, error) {
mux: http.NewServeMux(),
xffmw: xffmw,
+ clacks: ClackSet(strings.Split(envOr("CLACK_SET", "Ashlynn"), ",")),
patrons: pledges,
SignalBoost: people,
}
diff --git a/shell.nix b/shell.nix
index 6464c11..9453b2a 100644
--- a/shell.nix
+++ b/shell.nix
@@ -27,4 +27,6 @@ mkShell {
# tools
ispell
];
+
+ CLACK_SET = "Ashlynn,Terry Davis,Dennis Ritchie";
}