feat: access token check
This commit is contained in:
parent
7629f391ad
commit
6786f7ac00
3 changed files with 130 additions and 28 deletions
|
|
@ -25,18 +25,18 @@ import (
|
|||
var AppConfig Config
|
||||
|
||||
func main() {
|
||||
// if len(os.Args) != 2 {
|
||||
// AppConfig.Mode = "env"
|
||||
// } else {
|
||||
// AppConfig.Mode = "argv"
|
||||
// }
|
||||
if len(os.Args) != 2 {
|
||||
AppConfig.Mode = "env"
|
||||
} else {
|
||||
AppConfig.Mode = "argv"
|
||||
}
|
||||
|
||||
// err := InitConfig()
|
||||
// if err != nil {
|
||||
// log.Fatalf("Failed to init config: %v\n", err)
|
||||
// }
|
||||
err := InitConfig()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to init config: %v\n", err)
|
||||
}
|
||||
|
||||
pool, err := pgxpool.New(context.Background(), os.Getenv("DATABASE_URL"))
|
||||
pool, err := pgxpool.New(context.Background(), AppConfig.DdUrl)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
|
@ -47,16 +47,11 @@ func main() {
|
|||
r := gin.Default()
|
||||
|
||||
r.Use(middleware.CSRFMiddleware())
|
||||
// jwt middle will be here
|
||||
r.Use(middleware.JWTAuthMiddleware(AppConfig.JwtPrivateKey))
|
||||
|
||||
queries := sqlc.New(pool)
|
||||
|
||||
// === RabbitMQ setup ===
|
||||
rmqURL := os.Getenv("RABBITMQ_URL")
|
||||
if rmqURL == "" {
|
||||
rmqURL = "amqp://guest:guest@rabbitmq:5672/"
|
||||
}
|
||||
|
||||
rmqConn, err := amqp091.Dial(rmqURL)
|
||||
rmqConn, err := amqp091.Dial(AppConfig.rmqURL)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to connect to RabbitMQ: %v", err)
|
||||
}
|
||||
|
|
@ -68,7 +63,7 @@ func main() {
|
|||
server := handlers.NewServer(queries, publisher, rpcClient)
|
||||
|
||||
r.Use(cors.New(cors.Config{
|
||||
AllowOrigins: []string{"*"}, // allow all origins, change to specific domains in production
|
||||
AllowOrigins: []string{AppConfig.ServiceAddress},
|
||||
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "PATCH"},
|
||||
AllowHeaders: []string{"Origin", "Content-Type", "Accept"},
|
||||
ExposeHeaders: []string{"Content-Length"},
|
||||
|
|
@ -78,7 +73,7 @@ func main() {
|
|||
|
||||
oapi.RegisterHandlers(r, oapi.NewStrictHandler(
|
||||
server,
|
||||
// сюда можно добавить middlewares, если нужно
|
||||
|
||||
[]oapi.StrictMiddlewareFunc{},
|
||||
))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue