GraphQL API and utilities for the rpdata project
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.

46 lines
931 B

  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "log"
  6. "net/http"
  7. "runtime/debug"
  8. "git.aiterp.net/rpdata/api/graph2"
  9. "git.aiterp.net/rpdata/api/internal/store"
  10. logModel "git.aiterp.net/rpdata/api/model/log"
  11. "github.com/99designs/gqlgen/handler"
  12. )
  13. func main() {
  14. err := store.Init()
  15. if err != nil {
  16. log.Fatalln("Failed to init store:", err)
  17. }
  18. http.Handle("/", handler.Playground("RPData API", "/query"))
  19. http.Handle("/query", handler.GraphQL(
  20. graph2.New(),
  21. handler.RecoverFunc(func(ctx context.Context, err interface{}) error {
  22. // send this panic somewhere
  23. log.Println(err)
  24. log.Println(string(debug.Stack()))
  25. return fmt.Errorf("shit")
  26. }),
  27. ))
  28. go updateCharacters()
  29. log.Fatal(http.ListenAndServe(":8081", nil))
  30. }
  31. func updateCharacters() {
  32. n, err := logModel.UpdateAllCharacters()
  33. if err != nil {
  34. log.Println("Charcter updated stopped:", err)
  35. }
  36. log.Println("Updated characters on", n, "logs")
  37. }