-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
main.go
66 lines (54 loc) · 1.58 KB
/
main.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"embed"
"fmt"
"os"
"runtime/pprof"
"time"
"github.com/spf13/viper"
"github.com/tphakala/birdnet-go/cmd"
"github.com/tphakala/birdnet-go/internal/conf"
"github.com/tphakala/birdnet-go/internal/httpcontroller"
)
// buildTime is the time when the binary was built.
var buildDate string
//go:embed assets/*
var assetsFs embed.FS
//go:embed views/*
var viewsFs embed.FS
func main() {
// Check if profiling is enabled
if os.Getenv("BIRDNET_GO_PROFILE") == "1" {
fmt.Println("Profiling enabled")
// Create a unique profile name with timestamp
now := time.Now()
profilePath := fmt.Sprintf("profile_%s.pprof", now.Format("20060102_150405"))
f, err := os.Create(profilePath)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating profile file: %v\n", err)
os.Exit(1)
}
defer f.Close()
if err := pprof.StartCPUProfile(f); err != nil {
fmt.Fprintf(os.Stderr, "Error starting CPU profile: %v\n", err)
os.Exit(1)
}
defer pprof.StopCPUProfile()
}
// publish the embedded assets and views directories to controller package
httpcontroller.AssetsFs = assetsFs
httpcontroller.ViewsFs = viewsFs
// Load the configuration
settings := conf.Setting()
if settings == nil {
fmt.Fprintf(os.Stderr, "Error loading configuration\n")
os.Exit(1)
}
fmt.Printf("🐦 \033[37mBirdNET-Go build date: %s, using config file: %s\033[0m\n", buildDate, viper.ConfigFileUsed())
// Execute the root command
rootCmd := cmd.RootCommand(settings)
if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "Command execution error: %v\n", err)
os.Exit(1)
}
}