Files
FastDeploy/fastdeploy/golang_router/internal/router/router.go
T
mouxin 0a92e96f20 [Feature] Add Golang-based Router for Request Scheduling and Load Balancing (#5882)
* [Feature] add golang router

* [Feature] add golang router

* [Feature] add golang router

* [Feature] add golang router

* [Feature] add golang router

* [Feature] Add Golang-based Router for Request Scheduling and Load Balancing

* [Feature] Add Golang-based Router for Request Scheduling and Load Balancing

* [Feature] Add Golang-based Router for Request Scheduling and Load Balancing

* [Feature] Add Golang-based Router for Request Scheduling and Load Balancing

---------

Co-authored-by: mouxin <mouxin@baidu.com>
2026-01-07 21:28:08 +08:00

37 lines
968 B
Go

package router
import (
"github.com/PaddlePaddle/FastDeploy/router/internal/config"
"github.com/PaddlePaddle/FastDeploy/router/internal/middleware"
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/PaddlePaddle/FastDeploy/router/internal/gateway"
"github.com/PaddlePaddle/FastDeploy/router/internal/manager"
)
func New(cfg *config.Config) *gin.Engine {
// Set Gin mode
gin.SetMode(cfg.Server.Mode)
r := gin.New()
// Global middleware
r.Use(middleware.Logger())
r.Use(middleware.Recovery())
// API route group
v1 := r.Group("/v1")
{
v1.POST("/chat/completions", gateway.ChatCompletions)
v1.POST("/completions", gateway.ChatCompletions)
}
r.POST("/register", manager.RegisterInstance)
r.GET("/registered_number", manager.RegisteredNumber)
r.GET("/registered", manager.Registered)
r.GET("/health_generate", manager.HealthGenerate)
r.GET("/metrics", gin.WrapH(promhttp.Handler()))
return r
}