Skip to content

Commit 0e672ef

Browse files
enocommarkmandel
authored andcommitted
Shrink main func to resolve gocyclo warning
Fixes agones-dev#178
1 parent 3f2abb2 commit 0e672ef

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

examples/simple-udp/server/main.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ import (
2121
"net"
2222
"os"
2323
"strings"
24-
2524
"time"
2625

2726
"agones.dev/agones/sdks/go"
2827
)
2928

3029
// main starts a UDP server that received 1024 byte sized packets at at time
3130
// converts the bytes to a string, and logs the output
32-
func main() { // nolint: gocyclo
31+
func main() {
3332
port := flag.String("port", "7654", "The port to listen to udp traffic on")
3433
flag.Parse()
3534
if ep := os.Getenv("PORT"); ep != "" {
@@ -50,7 +49,7 @@ func main() { // nolint: gocyclo
5049
}
5150

5251
log.Print("Starting Health Ping")
53-
stop := make(chan bool)
52+
stop := make(chan struct{})
5453
go doHealth(s, stop)
5554

5655
log.Print("Marking this server as ready")
@@ -60,6 +59,10 @@ func main() { // nolint: gocyclo
6059
log.Fatalf("Could not send ready message")
6160
}
6261

62+
readWriteLoop(conn, stop, s)
63+
}
64+
65+
func readWriteLoop(conn net.PacketConn, stop chan struct{}, s *sdk.SDK) {
6366
b := make([]byte, 1024)
6467
for {
6568
n, sender, err := conn.ReadFrom(b)
@@ -74,8 +77,8 @@ func main() { // nolint: gocyclo
7477
case "EXIT":
7578
log.Printf("Received EXIT command. Exiting.")
7679
// This tells Agones to shutdown this Game Server
77-
err := s.Shutdown()
78-
if err != nil {
80+
shutdownErr := s.Shutdown()
81+
if shutdownErr != nil {
7982
log.Printf("Could not shutdown")
8083
}
8184
os.Exit(0)
@@ -94,7 +97,7 @@ func main() { // nolint: gocyclo
9497
}
9598

9699
// doHealth sends the regular Health Pings
97-
func doHealth(sdk *sdk.SDK, stop <-chan bool) {
100+
func doHealth(sdk *sdk.SDK, stop <-chan struct{}) {
98101
tick := time.Tick(2 * time.Second)
99102
for {
100103
err := sdk.Health()

0 commit comments

Comments
 (0)