You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
859 B

  1. package cmd
  2. import (
  3. "github.com/arnaucube/gogame/config"
  4. "github.com/arnaucube/gogame/database"
  5. "github.com/arnaucube/gogame/endpoint"
  6. "github.com/arnaucube/gogame/services/gamesrv"
  7. "github.com/arnaucube/gogame/services/usersrv"
  8. "github.com/urfave/cli"
  9. )
  10. var ServerCommands = []cli.Command{
  11. {
  12. Name: "start",
  13. Aliases: []string{},
  14. Usage: "start the server",
  15. Action: start,
  16. },
  17. }
  18. func start(c *cli.Context) error {
  19. if err := config.MustRead(c); err != nil {
  20. return err
  21. }
  22. db, err := database.New(config.C.Mongodb.Url, config.C.Mongodb.Database)
  23. if err != nil {
  24. return err
  25. }
  26. // services
  27. gameservice := gamesrv.New(db)
  28. userservice := usersrv.New(db, gameservice)
  29. if err != nil {
  30. return err
  31. }
  32. apiService := endpoint.Serve(config.C, db, userservice, gameservice)
  33. apiService.Run(config.C.Server.ServiceApi)
  34. return nil
  35. }