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
+2
View File
@@ -8,9 +8,11 @@ PGURL='postgres://postgres:postgres@db:5432/postgres?sslmode=disable'
# SERVER
SERVER_PORT=8000
SECRET_KEY=my_very_secret_key
# MIGRATOR
MIGRATOR_PORT=3000
GOOSE_DRIVER=postgres
GOOSE_DBSTRING='user=postgres dbname=postgres sslmode=disable'
GOOSE_MIGRATION_DIR=migrations
+2
View File
@@ -4,10 +4,12 @@ import (
"api/src/configs"
"api/src/initializers"
"log/slog"
"os"
)
var APIServerCnf configs.APIserver
var PSQLCnf configs.PSQLConfig
var SecretKey = []byte(os.Getenv("SECRET_KEY"))
func main() {
slog.Info("Start")
+3
View File
@@ -5,6 +5,7 @@ go 1.22.5
require github.com/go-chi/chi/v5 v5.1.0
require (
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.6.0 // indirect
@@ -18,6 +19,8 @@ require (
)
require (
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/google/uuid v1.6.0
gorm.io/driver/postgres v1.5.9
gorm.io/gorm v1.25.11
+6
View File
@@ -3,6 +3,12 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
+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"`
}
}
-3
View File
@@ -38,9 +38,6 @@ services:
- db
volumes:
- goose:/migrations
environment:
- GOOSE_DRIVER=${GOOSE_DRIVER}
- GOOSE_DBSTRING=${GOOSE_DBSTRING}
command: goose up
volumes: