feat: 重构项目以符合 Go 规范,添加 OpenAI 接口适配,优化长文本朗读功能(切割后合并)

This commit is contained in:
王锦强
2025-03-09 13:02:28 +08:00
parent 539f6d9ef5
commit 8f2fd68ebe
31 changed files with 2487 additions and 647 deletions

View File

@@ -0,0 +1,22 @@
package middleware
import "net/http"
// CORS 处理跨域资源共享
func CORS(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// 设置CORS响应头
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
// 如果是预检请求直接返回200
if r.Method == http.MethodOptions {
w.WriteHeader(http.StatusOK)
return
}
// 继续下一个处理器
next.ServeHTTP(w, r)
})
}