main.go 718 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // API doc: https://wiki.summercamp.local/display/PIN/Pinguin+server+API
  2. package main
  3. import (
  4. "log"
  5. "net/http"
  6. _ "net/http/pprof"
  7. "os"
  8. "battlecamp-go-server/flag"
  9. "battlecamp-go-server/gameserver"
  10. )
  11. var gameServer gameserver.GameServer = gameserver.New()
  12. func main() {
  13. initLogging()
  14. log.Println("Game server version 0.1")
  15. initCliFlags()
  16. gameServer.Serve()
  17. }
  18. func initLogging() {
  19. logFile, err := os.Create("server.log")
  20. if err == nil {
  21. log.SetOutput(logFile)
  22. } else {
  23. log.Println("ERROR: Cannot open log file, using console.")
  24. log.Printf("%v=n", err)
  25. }
  26. }
  27. func initCliFlags() {
  28. flag.ParseFlags()
  29. if *flag.CpuProfile != "" {
  30. log.Println(http.ListenAndServe("localhost:6060", nil))
  31. }
  32. }