-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
86 lines (69 loc) · 1.98 KB
/
main.go
File metadata and controls
86 lines (69 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"log"
"net/http"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"github.com/vhybZApp/api/agent"
"github.com/vhybZApp/api/azure"
"github.com/vhybZApp/api/config"
"github.com/vhybZApp/api/database"
_ "github.com/vhybZApp/api/docs"
)
// @title Vhybz API
// @version 1.0.0
// @description API for Vhybz application with JWT authentication and Azure OpenAI integration
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url https://github.com/vhybZApp/api
// @contact.email support@vhybz.com
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost:8080
// @BasePath /
// @schemes http https
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
// @description JWT Authorization header using the Bearer scheme. Example: "Bearer {token}"
func main() {
// Load configuration
config.LoadConfig()
// Initialize database
if err := database.Initialize(); err != nil {
log.Fatalf("Error initializing database: %v", err)
}
// Create Gin router
r := gin.Default()
// Health check endpoint
r.GET("/health", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"status": "healthy",
})
})
// Swagger documentation
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
// Auth routes
auth := r.Group("/auth")
{
auth.POST("/register", register)
auth.POST("/login", login)
auth.POST("/refresh", refresh)
auth.GET("/profile", authMiddleware(), getProfile)
}
// Azure OpenAI routes
azureGroup := r.Group("/azure")
{
azureGroup.POST("/chat/completions", authMiddleware(), azure.ChatCompletion)
}
// Agent routes
agentGroup := r.Group("/agent")
{
agentGroup.POST("/agent/make-html", authMiddleware(), agent.MakeHTML)
}
// Start server
if err := r.Run(":8080"); err != nil {
log.Fatalf("Error starting server: %v", err)
}
}