Skip to content

Commit 9cb3787

Browse files
committed
Cleanup root_run.
1 parent 716c6c7 commit 9cb3787

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

Dockerfile-devel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ENV PATH=$PATH:$PROJECT_PATH/build
55
ENV CGO_ENABLED=0
66
ENV GO_EXTRA_BUILD_ARGS="-a -installsuffix cgo"
77

8-
RUN apk add --no-cache ca-certificates tzdata make git bash alpine-sdk
8+
RUN apk add --no-cache ca-certificates tzdata make git bash
99

1010
RUN mkdir -p $PROJECT_PATH
1111
COPY . $PROJECT_PATH

cmd/lora-packet-multiplexer/cmd/root_run.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,20 @@ import (
1313
"github.com/brocaar/lora-packet-multiplexer/internal/multiplexer"
1414
)
1515

16+
var mp *multiplexer.Multiplexer
17+
1618
func run(cmd *cobra.Command, args []string) error {
17-
m, err := multiplexer.New(config.C.PacketMultiplexer)
18-
if err != nil {
19-
return errors.Wrap(err, "new multiplexer error")
19+
20+
tasks := []func() error{
21+
setLogLevel,
22+
printStartMessage,
23+
setupMultiplexer,
24+
}
25+
26+
for _, t := range tasks {
27+
if err := t(); err != nil {
28+
log.Fatal(err)
29+
}
2030
}
2131

2232
sigChan := make(chan os.Signal)
@@ -25,7 +35,7 @@ func run(cmd *cobra.Command, args []string) error {
2535
log.WithField("signal", <-sigChan).Info("signal received")
2636
go func() {
2737
log.Warning("stopping lora-packet-multiplexer")
28-
if err := m.Close(); err != nil {
38+
if err := mp.Close(); err != nil {
2939
log.Fatal(err)
3040
}
3141
exitChan <- struct{}{}
@@ -38,3 +48,26 @@ func run(cmd *cobra.Command, args []string) error {
3848

3949
return nil
4050
}
51+
52+
func setLogLevel() error {
53+
log.SetLevel(log.Level(uint8(config.C.General.LogLevel)))
54+
return nil
55+
}
56+
57+
func printStartMessage() error {
58+
log.WithFields(log.Fields{
59+
"version": version,
60+
"docs": "https://www.loraserver.io/",
61+
}).Info("starting LoRa Packet Multiplexer")
62+
return nil
63+
}
64+
65+
func setupMultiplexer() error {
66+
var err error
67+
mp, err = multiplexer.New(config.C.PacketMultiplexer)
68+
if err != nil {
69+
return errors.Wrap(err, "new multiplexer error")
70+
}
71+
72+
return nil
73+
}

0 commit comments

Comments
 (0)