M Makefile => Makefile +2 -1
@@ 4,9 4,10 @@ SRC != find . -name '*.go' ! -name '*_test.go'
# Force using go's builtin dns resolver, instead of the system one, in order to
# produce a nice, clean, statically-linked executable!
-FLAGS = -tags netgo -ldflags="-X main.Version=$(shell git describe --always --dirty --tags)"
+FLAGS = -tags netgo
$(BINDIR)/$(NAME): $(SRC)
+ go generate
go build -o $(BINDIR) $(FLAGS)
all: $(NAME)
M main.go => main.go +11 -1
@@ 4,6 4,7 @@ import (
"bufio"
"crypto/tls"
"crypto/x509"
+ _ "embed"
"errors"
"flag"
"fmt"
@@ 13,6 14,7 @@ import (
"net/url"
"os"
"path"
+ "strings"
"sync"
"time"
@@ 26,7 28,9 @@ const (
GeminiMaxRequestSize = 1024
)
-var Version = "unknown"
+//go:generate sh -c "git describe --always --dirty --tags | xargs >version.txt"
+//go:embed version.txt
+var Version string
type ErrNotFound struct {
Reason string
@@ 228,6 232,12 @@ func loadCertificates(cfg *hodhod.Config) (certs []tls.Certificate, err error) {
}
func main() {
+ if Version == "" {
+ Version = "unknown"
+ } else {
+ Version = strings.TrimSpace(Version)
+ }
+
configFile := flag.String("config", "config.json", "Path to config file")
showVersion := flag.Bool("version", false, "Print hodhod version")
flag.Parse()