~elektito/hodhod

bfce1d9be12c36e805573ad26dc3fa5f548cd881 — Mostafa Razavi 1 year, 2 months ago b98038c
Use go:generate to set version number

I'm hoping (but not sure!) this will fix the version number of the
program when installed using "go install". Currently, installing through
"go install" does not set the version number (because makefile is not
invoked).
2 files changed, 13 insertions(+), 2 deletions(-)

M Makefile
M main.go
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()