This repository has been archived on 2026-04-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
core/server/main.go
2026-02-03 17:20:06 -05:00

108 lines
3.3 KiB
Go

package main
import (
"log"
"os"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
func main() {
// Load .env file if present
godotenv.Load()
// Get port from environment
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
// Initialize router
r := gin.Default()
// CORS middleware
r.Use(func(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", "*")
c.Header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
c.Header("Access-Control-Allow-Headers", "Content-Type, Authorization")
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(204)
return
}
c.Next()
})
// Health check
r.GET("/health", func(c *gin.Context) {
c.JSON(200, gin.H{"status": "ok"})
})
// API routes
api := r.Group("/api/v1")
{
// Auth routes
api.POST("/auth/register", handleRegister)
api.POST("/auth/login", handleLogin)
// Protected routes
protected := api.Group("")
protected.Use(authMiddleware())
{
// Chats
protected.GET("/chats", handleListChats)
protected.POST("/chats", handleCreateChat)
protected.GET("/chats/:id", handleGetChat)
protected.PUT("/chats/:id", handleUpdateChat)
protected.DELETE("/chats/:id", handleDeleteChat)
// Messages
protected.GET("/chats/:id/messages", handleGetMessages)
protected.POST("/chats/:id/messages", handleCreateMessage)
// Settings
protected.GET("/settings", handleGetSettings)
protected.PUT("/settings", handleUpdateSettings)
// API Configs
protected.GET("/api-configs", handleListAPIConfigs)
protected.POST("/api-configs", handleCreateAPIConfig)
protected.DELETE("/api-configs/:id", handleDeleteAPIConfig)
// Models (proxy to configured API)
protected.GET("/models", handleListModels)
}
}
log.Printf("🔀 Chat Switchboard API starting on port %s", port)
r.Run(":" + port)
}
// Placeholder handlers - implement in handlers/ package
func handleRegister(c *gin.Context) { c.JSON(501, gin.H{"error": "not implemented"}) }
func handleLogin(c *gin.Context) { c.JSON(501, gin.H{"error": "not implemented"}) }
func handleListChats(c *gin.Context) { c.JSON(501, gin.H{"error": "not implemented"}) }
func handleCreateChat(c *gin.Context) { c.JSON(501, gin.H{"error": "not implemented"}) }
func handleGetChat(c *gin.Context) { c.JSON(501, gin.H{"error": "not implemented"}) }
func handleUpdateChat(c *gin.Context) { c.JSON(501, gin.H{"error": "not implemented"}) }
func handleDeleteChat(c *gin.Context) { c.JSON(501, gin.H{"error": "not implemented"}) }
func handleGetMessages(c *gin.Context) { c.JSON(501, gin.H{"error": "not implemented"}) }
func handleCreateMessage(c *gin.Context) { c.JSON(501, gin.H{"error": "not implemented"}) }
func handleGetSettings(c *gin.Context) { c.JSON(501, gin.H{"error": "not implemented"}) }
func handleUpdateSettings(c *gin.Context) { c.JSON(501, gin.H{"error": "not implemented"}) }
func handleListAPIConfigs(c *gin.Context) { c.JSON(501, gin.H{"error": "not implemented"}) }
func handleCreateAPIConfig(c *gin.Context) {
c.JSON(501, gin.H{"error": "not implemented"})
}
func handleDeleteAPIConfig(c *gin.Context) {
c.JSON(501, gin.H{"error": "not implemented"})
}
func handleListModels(c *gin.Context) { c.JSON(501, gin.H{"error": "not implemented"}) }
func authMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
// TODO: Implement JWT validation
c.Next()
}
}