Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: log version at startup #178

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}