-
Notifications
You must be signed in to change notification settings - Fork 7
/
start.go
53 lines (48 loc) · 1.12 KB
/
start.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
package command
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/lunarway/release-manager/cmd/server/http"
"github.com/lunarway/release-manager/internal/log"
"github.com/lunarway/release-manager/internal/slack"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
func NewStart(options *http.Options) *cobra.Command {
var command = &cobra.Command{
Use: "start",
Short: "start the release-manager",
RunE: func(c *cobra.Command, args []string) error {
done := make(chan error, 1)
client, err := slack.NewClient(options.SlackAuthToken)
if err != nil {
return err
}
go func() {
err := http.NewServer(options, client)
if err != nil {
done <- errors.WithMessage(err, "new http server")
return
}
}()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
select {
case sig := <-sigs:
done <- fmt.Errorf("received os signal '%s'", sig)
}
}()
err = <-done
if err != nil {
log.Errorf("Exited unknown error: %v", err)
os.Exit(1)
}
log.Infof("Program ended")
return nil
},
}
return command
}