1. 调整go.mod将Go版本升级至1.26 2. 新增速率限制和并发限制中间件,将其加入路由中间件链 3. 重构TTS处理逻辑,将限流逻辑迁移至中间件统一处理 4. 优化CORS中间件代码,移除冗余日志和格式调整
31 lines
798 B
Go
31 lines
798 B
Go
package router
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/volcano-tts/tts-api/controller"
|
|
"github.com/volcano-tts/tts-api/middleware"
|
|
)
|
|
|
|
func Setup() *mux.Router {
|
|
r := mux.NewRouter()
|
|
|
|
r.Use(middleware.CORS)
|
|
r.Use(middleware.SecurityHeaders)
|
|
r.Use(middleware.RateLimit)
|
|
r.Use(middleware.ConcurrencyLimit)
|
|
r.Use(middleware.Logger)
|
|
|
|
r.HandleFunc("/v1/audio/speech", controller.OpenaiTTSHandler).Methods("POST", "OPTIONS")
|
|
r.HandleFunc("/health", controller.HealthHandler).Methods("GET")
|
|
r.HandleFunc("/dashboard", func(w http.ResponseWriter, r *http.Request) {
|
|
http.ServeFile(w, r, "health.html")
|
|
}).Methods("GET")
|
|
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
http.Redirect(w, r, "/dashboard", http.StatusFound)
|
|
}).Methods("GET")
|
|
|
|
return r
|
|
}
|