mdidle ware set
This commit is contained in:
@@ -8,9 +8,11 @@ PGURL='postgres://postgres:postgres@db:5432/postgres?sslmode=disable'
|
|||||||
|
|
||||||
# SERVER
|
# SERVER
|
||||||
SERVER_PORT=8000
|
SERVER_PORT=8000
|
||||||
|
SECRET_KEY=my_very_secret_key
|
||||||
|
|
||||||
# MIGRATOR
|
# MIGRATOR
|
||||||
MIGRATOR_PORT=3000
|
MIGRATOR_PORT=3000
|
||||||
GOOSE_DRIVER=postgres
|
GOOSE_DRIVER=postgres
|
||||||
GOOSE_DBSTRING='user=postgres dbname=postgres sslmode=disable'
|
GOOSE_DBSTRING='user=postgres dbname=postgres sslmode=disable'
|
||||||
GOOSE_MIGRATION_DIR=migrations
|
GOOSE_MIGRATION_DIR=migrations
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ import (
|
|||||||
"api/src/configs"
|
"api/src/configs"
|
||||||
"api/src/initializers"
|
"api/src/initializers"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
var APIServerCnf configs.APIserver
|
var APIServerCnf configs.APIserver
|
||||||
var PSQLCnf configs.PSQLConfig
|
var PSQLCnf configs.PSQLConfig
|
||||||
|
var SecretKey = []byte(os.Getenv("SECRET_KEY"))
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
slog.Info("Start")
|
slog.Info("Start")
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ go 1.22.5
|
|||||||
require github.com/go-chi/chi/v5 v5.1.0
|
require github.com/go-chi/chi/v5 v5.1.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
|
||||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||||
github.com/jackc/pgx/v5 v5.6.0 // indirect
|
github.com/jackc/pgx/v5 v5.6.0 // indirect
|
||||||
@@ -18,6 +19,8 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
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
|
github.com/google/uuid v1.6.0
|
||||||
gorm.io/driver/postgres v1.5.9
|
gorm.io/driver/postgres v1.5.9
|
||||||
gorm.io/gorm v1.25.11
|
gorm.io/gorm v1.25.11
|
||||||
|
|||||||
@@ -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/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 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
|
||||||
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
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 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
)
|
||||||
|
|
||||||
|
func Register() {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gorm.io/driver/postgres"
|
"gorm.io/driver/postgres"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@@ -53,7 +54,16 @@ func InitDBconnection() {
|
|||||||
func InitChiRouting() {
|
func InitChiRouting() {
|
||||||
slog.Info("Init routing")
|
slog.Info("Init routing")
|
||||||
r := chi.NewRouter()
|
r := chi.NewRouter()
|
||||||
|
|
||||||
|
// middlewares
|
||||||
r.Use(middleware.Logger)
|
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) {
|
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write([]byte("welcome developer! Cool."))
|
w.Write([]byte("welcome developer! Cool."))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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"`
|
||||||
|
}
|
||||||
@@ -8,4 +8,4 @@ type User struct {
|
|||||||
Email string `json:"email" gorm:"type:string;index"`
|
Email string `json:"email" gorm:"type:string;index"`
|
||||||
Password string `json:"password" gorm:"type:string;index"`
|
Password string `json:"password" gorm:"type:string;index"`
|
||||||
Phone string `json:"phone" gorm:"type:string;index"`
|
Phone string `json:"phone" gorm:"type:string;index"`
|
||||||
}
|
}
|
||||||
@@ -38,9 +38,6 @@ services:
|
|||||||
- db
|
- db
|
||||||
volumes:
|
volumes:
|
||||||
- goose:/migrations
|
- goose:/migrations
|
||||||
environment:
|
|
||||||
- GOOSE_DRIVER=${GOOSE_DRIVER}
|
|
||||||
- GOOSE_DBSTRING=${GOOSE_DBSTRING}
|
|
||||||
command: goose up
|
command: goose up
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
Reference in New Issue
Block a user