re-arrange for better maintainability

This commit is contained in:
Jonas Große Sundrup 2023-12-30 00:05:50 +01:00
parent 71114492ed
commit 530d70a2d6
No known key found for this signature in database
GPG key ID: 5B587ADC0531D442

21
main.go
View file

@ -73,12 +73,21 @@ func main() {
if isSocketActivated { if isSocketActivated {
l, err = net.FileListener(os.NewFile(3, "systemd-socket")) l, err = net.FileListener(os.NewFile(3, "systemd-socket"))
fmt.Println("Listening on systemd-socket") fmt.Println("Listening on systemd-socket")
conn, err := l.Accept()
if err != nil {
fmt.Println("Error accepting: ", err.Error())
os.Exit(1)
}
handleRequest(conn)
if *restart {
restartUISoftware()
}
} else { } else {
l, err = net.Listen("tcp", *CONN_HOST+":"+*CONN_PORT) l, err = net.Listen("tcp", *CONN_HOST+":"+*CONN_PORT)
fmt.Println("Listening on " + *CONN_HOST + ":" + *CONN_PORT) fmt.Println("Listening on " + *CONN_HOST + ":" + *CONN_PORT)
}
check(err)
defer l.Close() // Close the listener when the application closes.
for { for {
// Listen for an incoming connection. // Listen for an incoming connection.
@ -93,12 +102,12 @@ func main() {
restartUISoftware() restartUISoftware()
} }
if isSocketActivated {
break
} }
}
check(err)
defer l.Close() // Close the listener when the application closes.
} }
}
func debug(msg ...string) { func debug(msg ...string) {
if LOG_LEVEL == "debug" { if LOG_LEVEL == "debug" {