No Description

main.go 939B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package main
  2. import (
  3. "context"
  4. "log"
  5. "net/http"
  6. "strconv"
  7. "./core/database"
  8. "./core/errorHandler"
  9. req "./core/request"
  10. res "./core/response"
  11. "./src/lib/auth"
  12. )
  13. func main() {
  14. initDatabase()
  15. initAuthService()
  16. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  17. var Errors errorHandler.Errors
  18. ctx := context.WithValue(r.Context(), "Username", "William")
  19. r.WithContext(ctx)
  20. res.SetResponseWriter(w)
  21. req.SetRequest(r)
  22. if !database.IsConnected {
  23. Errors.InternalError("Conexão com a base de dados falhou!")
  24. res.JSON(Errors)
  25. return
  26. }
  27. Routes.Match(w, r)
  28. })
  29. log.Fatal(http.ListenAndServe(":"+strconv.Itoa(SERVER_PORT), nil))
  30. }
  31. func initDatabase() {
  32. database.Init(
  33. database.Config{
  34. DATABASE_HOST,
  35. DATABASE_PORT,
  36. DATABASE_USER,
  37. DATABASE_PASS,
  38. DATABASE_SCHEMA,
  39. })
  40. }
  41. func initAuthService() {
  42. auth.Config(
  43. auth.ServiceConfig{
  44. AUTHENTICATION_SERVICE,
  45. })
  46. }