add i18n support

This commit is contained in:
landaiqing
2024-11-12 22:59:39 +08:00
parent 97ca3fc7b0
commit ae743ba8a6
62 changed files with 4468 additions and 2797 deletions

View File

@@ -0,0 +1,12 @@
package middleware
import "net/http"
func CORSMiddleware() func(http.Header) {
return func(header http.Header) {
header.Set("Access-Control-Allow-Origin", "*")
header.Add("Access-Control-Allow-Headers", "UserHeader1, UserHeader2")
header.Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, PATCH")
header.Set("Access-Control-Expose-Headers", "Content-Length, Content-Type")
}
}

View File

@@ -1,7 +1,16 @@
package middleware
import "net/http"
import (
"net/http"
func I18nMiddleware(w http.ResponseWriter, r *http.Request) {
"golang.org/x/text/language"
"schisandra-album-cloud-microservices/common/i18n"
)
func I18nMiddleware(next http.HandlerFunc) http.HandlerFunc {
return i18n.NewI18nMiddleware([]language.Tag{
language.English,
language.Chinese,
}, []string{"../../resources/language/active.en.toml", "../../resources/language/active.zh.toml"}).Handle(next)
}