12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package main
- import (
- "log"
- "net/http"
- "os"
- "github.com/andreanidouglas/auth/model"
- "github.com/andreanidouglas/auth/routes"
- "golang.org/x/crypto/bcrypt"
- )
- func health_check(w http.ResponseWriter, r *http.Request) {
- w.WriteHeader(200)
- }
- func main() {
- db := model.NewDb("./auth.db")
- db.Setup()
- passwd, err := bcrypt.GenerateFromPassword([]byte("d5022a"), 5)
- if err != nil {
- log.Fatalf("Could not create password: %v", err)
- }
- u := model.User{Email: "cmtedouglas@hotmail.com", Password: string(passwd), Name: "Douglas", ID: 1}
- model.CreateUser(&u, &db)
- logging := log.New(os.Stdout, "AUTH-GO: ", 0)
- r := routes.New(logging, db)
- ur := routes.UserRoutes{}
- ar := routes.AuthRoutes{}
- ur.Register(&r)
- ar.Register(&r)
- for _, route := range r.Routes {
- logging.Printf("Registered [%s] %s protected: %v\n", route.Method, route.Path, route.Authentication)
- http.HandleFunc(route.Path, route.Handler)
- }
- logging.Fatalln(http.ListenAndServe(":3535", nil))
- }
|