~bigbes/huntsman

ref: 783841b91eafd678cb3895cfcc8dfd89f290ece7 huntsman/cmd/server/main.go -rw-r--r-- 1.0 KiB
783841b9 — Eugene Blikh Initial commit: multi-provider search router 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Command server runs the multi-provider search helper.
package main

import (
	"context"
	"flag"
	"fmt"
	"log/slog"
	"os"
	"os/signal"
	"syscall"

	"go.bigb.es/auxilia/scribe"

	"sourcecraft.dev/bigbes/huntsman/internal/app"
)

// Set by goreleaser / -ldflags.
var (
	version = "dev"
	commit  = "none"
	date    = "unknown"
)

func main() {
	os.Exit(run())
}

func run() int {
	configPath := flag.String("config", "config.yaml", "path to config file")
	showVersion := flag.Bool("version", false, "print version and exit")
	flag.Parse()

	if *showVersion {
		fmt.Printf("huntsman %s (commit %s, built %s)\n", version, commit, date)
		return 0
	}

	ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
	defer stop()

	a, err := app.New(ctx, *configPath, app.BuildInfo{Version: version, Commit: commit, Date: date})
	if err != nil {
		slog.Error("startup failed", scribe.Err(err))
		return 1
	}
	if err := a.Run(ctx); err != nil {
		slog.Error("run failed", scribe.Err(err))
		return 1
	}
	return 0
}