Skip to content

Commit

Permalink
feat(main): Add version flag to display application version (#45)
Browse files Browse the repository at this point in the history
* feat(main): Add version flag to display application version #41

Signed-off-by: Mert Şişmanoğlu <[email protected]>

* feat(goreleaser): Add versioning support and static build flags

- s
- w
- extldflags static
- X main.Version = APP_VERSION

Signed-off-by: Mert Şişmanoğlu <[email protected]>

---------

Signed-off-by: Mert Şişmanoğlu <[email protected]>
  • Loading branch information
mertssmnoglu authored Feb 2, 2025
1 parent 93122c5 commit 14aff9e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ project_name: capture
builds:
- id: capture
main: ./cmd/capture
ldflags:
- -s -w
- -extldflags "-static"
- -X "main.Version={{.Version}}"
env:
- CGO_ENABLED=0
goos:
Expand Down Expand Up @@ -34,6 +38,7 @@ kos:
ldflags:
- -s -w
- -extldflags "-static"
- -X "main.Version={{.Version}}"
creation_time: "{{.CommitTimestamp}}"
sbom: spdx
env:
Expand Down
24 changes: 20 additions & 4 deletions cmd/capture/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
Expand All @@ -15,12 +17,26 @@ import (
"github.com/gin-gonic/gin"
)

var appConfig = config.NewConfig(
os.Getenv("PORT"),
os.Getenv("API_SECRET"),
)
var appConfig *config.Config

var Version = "develop" // This will be set during compile time using go build ldflags

func main() {
showVersion := flag.Bool("version", false, "Display the version of the capture")
flag.Parse()

// Check if the version flag is provided
if *showVersion {
fmt.Printf("Capture version: %s\n", Version)
os.Exit(0)
}

appConfig = config.NewConfig(
os.Getenv("PORT"),
os.Getenv("API_SECRET"),
)

// Initialize the Gin with default middlewares
r := gin.Default()
apiV1 := r.Group("/api/v1")
apiV1.Use(middleware.AuthRequired(appConfig.APISecret))
Expand Down

0 comments on commit 14aff9e

Please sign in to comment.