main.go 980 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package main
  2. import (
  3. "log"
  4. "net/http"
  5. "os"
  6. "github.com/andreanidouglas/auth/model"
  7. "github.com/andreanidouglas/auth/routes"
  8. "golang.org/x/crypto/bcrypt"
  9. )
  10. func health_check(w http.ResponseWriter, r *http.Request) {
  11. w.WriteHeader(200)
  12. }
  13. func main() {
  14. db := model.NewDb("./auth.db")
  15. db.Setup()
  16. passwd, err := bcrypt.GenerateFromPassword([]byte("d5022a"), 5)
  17. if err != nil {
  18. log.Fatalf("Could not create password: %v", err)
  19. }
  20. u := model.User{Email: "cmtedouglas@hotmail.com", Password: string(passwd), Name: "Douglas", ID: 1}
  21. model.CreateUser(&u, &db)
  22. logging := log.New(os.Stdout, "AUTH-GO: ", 0)
  23. r := routes.New(logging, db)
  24. ur := routes.UserRoutes{}
  25. ar := routes.AuthRoutes{}
  26. ur.Register(&r)
  27. ar.Register(&r)
  28. for _, route := range r.Routes {
  29. logging.Printf("Registered [%s] %s protected: %v\n", route.Method, route.Path, route.Authentication)
  30. http.HandleFunc(route.Path, route.Handler)
  31. }
  32. logging.Fatalln(http.ListenAndServe(":3535", nil))
  33. }