package restserver import ( "fmt" "io" "net/http" "git.ukamnya.ru/stulyaganov/RestApiv2/internal/bd/model" "git.ukamnya.ru/stulyaganov/RestApiv2/pkg/utils/password" ) func (r *RestServer) configureRouterUser() { r.router.HandleFunc("/api/register", r.chekUserRegistr(r.HandleFuncRegUser())).Methods("POST") r.router.HandleFunc("/api/login", r.HandleFuncLoginUser()).Methods("POST") r.router.HandleFunc("/api/logout", r.HandleFuncLogOutUser()).Methods("POST") } func (r *RestServer) HandleFuncRegUser() http.HandlerFunc { return func(w http.ResponseWriter, res *http.Request) { users := res.Context().Value(ContextKeyUser).(*model.User) hash, err := password.HashPassword(users.Password) if err != nil { r.logger.Error(err) } users.Password = string(*hash) err = r.db.User().Create(users) if err != nil { r.logger.Error(err) } else { io.WriteString(w, `{"data":"Пользователь создан"}`) } } } func (r *RestServer) HandleFuncLoginUser() http.HandlerFunc { return func(w http.ResponseWriter, res *http.Request) { fmt.Println("login") } } func (r *RestServer) HandleFuncLogOutUser() http.HandlerFunc { return func(w http.ResponseWriter, res *http.Request) { fmt.Println("login") } }