mdidle ware set

This commit is contained in:
valitovgaziz
2024-08-12 08:49:04 +05:00
parent 32daac3a49
commit 5cbb3237e0
9 changed files with 51 additions and 4 deletions
+8
View File
@@ -0,0 +1,8 @@
package auth
import (
)
func Register() {
}
+10
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"os"
"time"
"gorm.io/driver/postgres"
"gorm.io/gorm"
@@ -53,7 +54,16 @@ func InitDBconnection() {
func InitChiRouting() {
slog.Info("Init routing")
r := chi.NewRouter()
// middlewares
r.Use(middleware.Logger)
r.Use(middleware.Timeout(60 * time.Second))
r.Use(middleware.RequestID)
r.Use(middleware.CleanPath)
r.Use(middleware.Heartbeat("/ping"))
r.Use(middleware.NoCache)
r.Use(middleware.Recoverer)
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("welcome developer! Cool."))
})
+19
View File
@@ -0,0 +1,19 @@
package models
import (
"os"
"github.com/golang-jwt/jwt/v4"
)
var jwtKey = []byte(os.Getenv("SECRET_KEY"))
type Crenetials struct {
Email string `json:"email"`
Password string `json:"password"`
}
type Claims struct {
jwt.RegisteredClaims
Email string `json:"email"`
}
+1 -1
View File
@@ -8,4 +8,4 @@ type User struct {
Email string `json:"email" gorm:"type:string;index"`
Password string `json:"password" gorm:"type:string;index"`
Phone string `json:"phone" gorm:"type:string;index"`
}
}