Skip to content

Commit

Permalink
feat: log version at startup (#178)
Browse files Browse the repository at this point in the history
Fixes #132
  • Loading branch information
agaffney authored Jul 31, 2024
1 parent c2a1b8d commit 611cb92
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ BINARIES=$(shell cd $(ROOT_DIR)/cmd && ls -1 | grep -v ^common)
GOMODULE=$(shell grep ^module $(ROOT_DIR)/go.mod | awk '{ print $$2 }')

# Set version strings based on git tag and current ref
GO_LDFLAGS=-ldflags "-s -w"
GO_LDFLAGS=-ldflags "-s -w -X '$(GOMODULE)/internal/version.Version=$(shell git describe --tags --exact-match 2>/dev/null)' -X '$(GOMODULE)/internal/version.CommitHash=$(shell git rev-parse --short HEAD)'"

.PHONY: build mod-tidy clean format golines test

Expand Down
7 changes: 6 additions & 1 deletion cmd/cdnsd/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Blink Labs Software
// Copyright 2024 Blink Labs Software
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
Expand All @@ -20,6 +20,7 @@ import (
"github.com/blinklabs-io/cdnsd/internal/indexer"
"github.com/blinklabs-io/cdnsd/internal/logging"
"github.com/blinklabs-io/cdnsd/internal/state"
"github.com/blinklabs-io/cdnsd/internal/version"
)

var cmdlineFlags struct {
Expand Down Expand Up @@ -54,6 +55,10 @@ func main() {
}
}()

logger.Info(
fmt.Sprintf("cdnsd %s started", version.GetVersionString()),
)

// Load state
if err := state.GetState().Load(); err != nil {
logger.Fatalf("failed to load state: %s", err)
Expand Down
23 changes: 23 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2024 Blink Labs Software
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

package version

import (
"fmt"
)

// These are populated at build time
var Version string
var CommitHash string

func GetVersionString() string {
if Version != "" {
return fmt.Sprintf("%s (commit %s)", Version, CommitHash)
} else {
return fmt.Sprintf("devel (commit %s)", CommitHash)
}
}

0 comments on commit 611cb92

Please sign in to comment.