Add version variables

This commit is contained in:
2025-05-24 18:30:21 +04:00
parent 9917f61db1
commit bad7b4a304
12 changed files with 196 additions and 133 deletions

View File

@@ -6,7 +6,7 @@ COPY go.mod go.sum ./
COPY ../../pkg ./pkg
COPY ../../cmd/api ./cmd/api
RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o api ./cmd/api/main.go
RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o api ./cmd/api
FROM gcr.io/distroless/static-debian12:latest

View File

@@ -2,8 +2,11 @@ package main
import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"github.com/aykhans/bsky-feedgen/pkg/api"
@@ -15,11 +18,21 @@ import (
_ "go.uber.org/automaxprocs"
)
type flags struct {
version bool
}
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go listenForTermination(func() { cancel() })
flags := getFlags()
if flags.version == true {
fmt.Printf("API version: %v\n", version)
os.Exit(0)
}
apiConfig, errMap := config.NewAPIConfig()
if errMap != nil {
logger.Log.Error("API ENV error", "error", errMap.ToStringMap())
@@ -59,3 +72,33 @@ func listenForTermination(do func()) {
<-sigChan
do()
}
func getFlags() *flags {
flags := &flags{}
flag.Usage = func() {
fmt.Println(
`Usage:
consumer [flags]
Flags:
-version version information
-h, -help Display this help message`)
}
flag.BoolVar(&flags.version, "version", false, "print version information")
flag.Parse()
if args := flag.Args(); len(args) > 0 {
if len(args) == 1 {
fmt.Printf("unexpected argument: %s\n\n", args[0])
} else {
fmt.Printf("unexpected arguments: %v\n\n", strings.Join(args, ", "))
}
flag.CommandLine.Usage()
os.Exit(1)
}
return flags
}

3
cmd/api/version.go Normal file
View File

@@ -0,0 +1,3 @@
package main
const version = "0.1.0"