first commit
This commit is contained in:
57
main.go
Normal file
57
main.go
Normal file
@@ -0,0 +1,57 @@
|
||||
// @title goaresv3 API
|
||||
// @version 1.0
|
||||
// @description Authentication API for goaresv3.
|
||||
// @BasePath /
|
||||
// @schemes http https
|
||||
// @securityDefinitions.apikey BearerAuth
|
||||
// @in header
|
||||
// @name Authorization
|
||||
// @description Paste the access token. Swagger UI sends it as: Bearer <token>
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/joho/godotenv"
|
||||
|
||||
"goaresv3/config"
|
||||
_ "goaresv3/docs"
|
||||
"goaresv3/pkg/middleware"
|
||||
"goaresv3/router"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := godotenv.Load(); err != nil {
|
||||
log.Println("no .env file found, relying on environment variables")
|
||||
}
|
||||
|
||||
if err := config.ConnectDB(); err != nil {
|
||||
log.Fatalf("database: %v", err)
|
||||
}
|
||||
|
||||
if err := config.RunAutoMigrate(); err != nil {
|
||||
log.Fatalf("migration: %v", err)
|
||||
}
|
||||
if err := config.SeedSecurityDefaults(); err != nil {
|
||||
log.Fatalf("security seed: %v", err)
|
||||
}
|
||||
|
||||
r := gin.Default()
|
||||
r.Use(middleware.DynamicCORS())
|
||||
r.Use(middleware.DynamicRateLimit())
|
||||
if err := r.SetTrustedProxies([]string{"127.0.0.1"}); err != nil {
|
||||
log.Fatalf("failed to set trusted proxies: %v", err)
|
||||
}
|
||||
router.Setup(r)
|
||||
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
}
|
||||
|
||||
if err := r.Run(":" + port); err != nil {
|
||||
log.Fatalf("server: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user