-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (42 loc) · 1.47 KB
/
main.go
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
// main.go
package main
import (
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"naas/handlers"
"naas/repositories"
"naas/service"
"os"
)
func main() {
// Initialize repositories
tenantRepo := repositories.NewTenantRepository()
namespaceRepo := repositories.NewNamespaceRepository()
// Initialize services
tenantService := service.NewTenantService(tenantRepo)
namespaceService := service.NewNamespaceService(namespaceRepo)
// Initialize handlers
tenantHandler := handlers.NewTenantHandler(tenantService)
namespaceHandler := handlers.NewNamespaceHandler(namespaceService)
// Initialize Gin router
router := gin.Default()
// Configure CORS middleware
config := cors.DefaultConfig()
config.AllowAllOrigins = true // Allow all origins for development
config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}
config.AllowHeaders = []string{"Origin", "Content-Type", "Accept", "Authorization"}
// Apply CORS middleware to your Gin instance
router.Use(cors.New(config))
// Define routes
router.POST("/tenants", tenantHandler.CreateTenant)
router.GET("/tenants", tenantHandler.ListTenants)
router.GET("/tenants/:id", tenantHandler.GetTenant)
router.POST("/namespaces/:tenantId", namespaceHandler.CreateNamespace)
router.GET("/namespaces/all/:tenantId", namespaceHandler.GetAllNamespaces)
router.GET("/namespaces/:tenantId/:name", namespaceHandler.GetNamespace)
// Start server
err := router.Run(":8082")
if err != nil {
os.Exit(1)
}
}