-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathmain.go
49 lines (42 loc) · 1.03 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
package main
import (
"context"
"errors"
"fmt"
"os"
"os/signal"
"github.com/simulot/immich-go/app/cmd"
)
// immich-go entry point
func main() {
ctx := context.Background()
err := immichGoMain(ctx)
if err != nil {
if e := context.Cause(ctx); e != nil {
err = e
}
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
// makes immich-go breakable with ^C and run it
func immichGoMain(ctx context.Context) error {
// Create a context with cancel function to gracefully handle Ctrl+C events
ctx, cancel := context.WithCancelCause(ctx)
// Handle Ctrl+C signal (SIGINT)
signalChannel := make(chan os.Signal, 1)
signal.Notify(signalChannel, os.Interrupt)
// Watch for ^C to be pressed
go func() {
<-signalChannel
fmt.Println("\nCtrl+C received. Shutting down...")
cancel(errors.New("Ctrl+C received")) // Cancel the context when Ctrl+C is received
}()
c, a := cmd.RootImmichGoCommand(ctx)
// let's start
err := c.ExecuteContext(ctx)
if err != nil && a.Log().GetSLog() != nil {
a.Log().Error(err.Error())
}
return err
}