From 0d1de2258553f16c9cd492f02f591c4d5457f958 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Fri, 19 Apr 2024 22:13:14 +0200 Subject: Brand executable with commit hash for server header --- nix/default.nix | 6 +++--- server.go | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/nix/default.nix b/nix/default.nix index e6102cf..2a7792a 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,7 +1,7 @@ { pkgs, self }: let - revision = "${self.lastModifiedDate}-${self.shortRev or "dirty"}"; - version = "unstable-${self.shortRev or "dirty"}"; + revision = "${self.lastModifiedDate}-${self.shortRev or self.dirtyShortRev or "dirty"}"; + version = self.shortRev or self.dirtyShortRev or "unstable-${self.lastModified}"; mkDocker = server: let PORT = 3000; @@ -63,7 +63,7 @@ rec { ${builder}/bin/build ''; modules = ./gomod2nix.toml; - ldflags = [ "-s" "-w" ]; + ldflags = [ "-s" "-w" "-X" "main.Commit=${version}" ]; }; docker = mkDocker server; docker-aarch64-linux = mkDocker (self.packages.aarch64-linux.server); diff --git a/server.go b/server.go index b34c933..69dca43 100644 --- a/server.go +++ b/server.go @@ -46,6 +46,8 @@ type Host struct { //go:embed all:public/* var fs embed.FS +var Commit string + func main() { config := Config{} if help, err := conf.Parse("", &config); err != nil { @@ -92,7 +94,6 @@ func main() { GETOnly: true, ReadTimeout: 5 * time.Minute, WriteTimeout: 5 * time.Minute, - ServerHeader: "Fiber", StrictRouting: true, UnescapePath: true, }) @@ -135,6 +136,7 @@ func main() { toplevel := fiber.New(fiber.Config{ DisableStartupMessage: config.Production, + ServerHeader: fmt.Sprintf("website (%s)", Commit), }) toplevel.Get("/health", func(c *fiber.Ctx) error { return c.SendStatus(fiber.StatusOK) -- cgit 1.4.1