✨ add i18n support
This commit is contained in:
@@ -4,7 +4,11 @@ import "github.com/zeromicro/go-zero/rest"
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
Auth struct {
|
||||
AccessSecret string
|
||||
AccessExpire int64
|
||||
}
|
||||
Mysql struct {
|
||||
Dsn string
|
||||
DataSource string
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ import (
|
||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.I18nMiddleware, serverCtx.SecurityHeadersMiddleware},
|
||||
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/internal/types"
|
||||
"schisandra-album-cloud-microservices/common/i18n"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -25,6 +26,10 @@ func NewAccountLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Acco
|
||||
|
||||
func (l *AccountLoginLogic) AccountLogin(req *types.AccountLoginRequest) (resp *types.LoginResponse, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
i18n.IsHasI18n(l.ctx)
|
||||
text := i18n.FormatText(l.ctx, "user.name", "landaiqing")
|
||||
|
||||
return
|
||||
return &types.LoginResponse{
|
||||
AccessToken: text,
|
||||
}, nil
|
||||
}
|
||||
|
@@ -1,19 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import "net/http"
|
||||
|
||||
type I18nMiddleware struct {
|
||||
}
|
||||
|
||||
func NewI18nMiddleware() *I18nMiddleware {
|
||||
return &I18nMiddleware{}
|
||||
}
|
||||
|
||||
func (m *I18nMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO generate middleware implement function, delete after code implementation
|
||||
|
||||
// Passthrough to next handler if need
|
||||
next(w, r)
|
||||
}
|
||||
}
|
@@ -6,14 +6,14 @@ import (
|
||||
"schisandra-album-cloud-microservices/app/auth/internal/config"
|
||||
"schisandra-album-cloud-microservices/app/auth/internal/middleware"
|
||||
"schisandra-album-cloud-microservices/common/core"
|
||||
"schisandra-album-cloud-microservices/common/ent/gen/entschema"
|
||||
"schisandra-album-cloud-microservices/common/ent"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
I18nMiddleware rest.Middleware
|
||||
SecurityHeadersMiddleware rest.Middleware
|
||||
DB *entschema.Client
|
||||
DB *ent.Client
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
@@ -21,6 +21,6 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
Config: c,
|
||||
I18nMiddleware: middleware.NewI18nMiddleware().Handle,
|
||||
SecurityHeadersMiddleware: middleware.NewSecurityHeadersMiddleware().Handle,
|
||||
DB: core.InitMySQL(c.Mysql.Dsn),
|
||||
DB: core.InitMySQL(c.Mysql.DataSource),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user