Skip to content

Commit

Permalink
Shrink main func to resolve gocyclo warning
Browse files Browse the repository at this point in the history
Fixes #178
  • Loading branch information
enocom authored and markmandel committed May 17, 2018
1 parent 3f2abb2 commit 0e672ef
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions examples/simple-udp/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ import (
"net"
"os"
"strings"

"time"

"agones.dev/agones/sdks/go"
)

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

log.Print("Starting Health Ping")
stop := make(chan bool)
stop := make(chan struct{})
go doHealth(s, stop)

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

readWriteLoop(conn, stop, s)
}

func readWriteLoop(conn net.PacketConn, stop chan struct{}, s *sdk.SDK) {
b := make([]byte, 1024)
for {
n, sender, err := conn.ReadFrom(b)
Expand All @@ -74,8 +77,8 @@ func main() { // nolint: gocyclo
case "EXIT":
log.Printf("Received EXIT command. Exiting.")
// This tells Agones to shutdown this Game Server
err := s.Shutdown()
if err != nil {
shutdownErr := s.Shutdown()
if shutdownErr != nil {
log.Printf("Could not shutdown")
}
os.Exit(0)
Expand All @@ -94,7 +97,7 @@ func main() { // nolint: gocyclo
}

// doHealth sends the regular Health Pings
func doHealth(sdk *sdk.SDK, stop <-chan bool) {
func doHealth(sdk *sdk.SDK, stop <-chan struct{}) {
tick := time.Tick(2 * time.Second)
for {
err := sdk.Health()
Expand Down

0 comments on commit 0e672ef

Please sign in to comment.