in containers-starter-kit/SdkGoWrapper/server.go [125:193]
func main() {
// Start the localhost server thread to provide information to the game server process on request
HttpServer(8090)
// Exit if no port is specified
if len(os.Args) < 2 {
fmt.Println("No port specified")
os.Exit(1)
}
// Get the port on cli args
log.Print("Getting the game server port")
port, err := strconv.Atoi(os.Args[1])
if err != nil {
panic(err)
}
log.Print("Game server port is: ", port)
log.Print("Starting GameLift wrapper")
// Initialize the Amazon GameLift Server SDK
err2 := server.InitSDK(server.ServerParameters{})
if err2 != nil {
log.Fatal(err2.Error())
}
// Make sure to call server.ProcessEnding() when the application quits.
// This tells GameLift the session has ended
defer server.ProcessEnding()
process := gameProcess{
Port: port,
Logs: server.LogParameters{
// The log path is not actually used with container fleets...
LogPaths: []string{"/local/game/logs/myserver.log"},
},
}
// Register our process to the Amazon GameLift service
err = server.ProcessReady(server.ProcessParameters{
OnStartGameSession: process.OnStartGameSession,
OnUpdateGameSession: process.OnUpdateGameSession,
OnProcessTerminate: process.OnProcessTerminate,
OnHealthCheck: process.OnHealthCheck,
LogParameters: process.Logs,
Port: process.Port,
})
if err != nil {
log.Fatal(err.Error())
}
// Create channel for SIGINT
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGINT)
// Wait until we get the interruption signal
for {
select {
case <-sigChan:
log.Print("Received SIGINT, shutting down...")
return
default:
time.Sleep(50 * time.Millisecond)
}
}
}