add casbin ent adapter & code migration

This commit is contained in:
landaiqing
2024-11-14 16:02:11 +08:00
parent 3b8e3df27a
commit b2d753e832
79 changed files with 1856 additions and 6462 deletions

View File

@@ -1,9 +1,14 @@
package response
import "schisandra-album-cloud-microservices/app/core/api/internal/types"
import (
"context"
// Success returns a success response with the given data.
func Success[T any](data T) *types.Response {
"schisandra-album-cloud-microservices/app/core/api/common/i18n"
"schisandra-album-cloud-microservices/app/core/api/internal/types"
)
// SuccessWithData returns a success response with the given data.
func SuccessWithData[T any](data T) *types.Response {
return &types.Response{
Code: 200,
Message: "success",
@@ -11,6 +16,15 @@ func Success[T any](data T) *types.Response {
}
}
// Success returns a success response with nil data.
func Success() *types.Response {
return &types.Response{
Code: 200,
Message: "success",
Data: nil,
}
}
// SuccessWithMessage returns a success response with the given message.
func SuccessWithMessage(message string) *types.Response {
return &types.Response{
@@ -30,7 +44,16 @@ func Error() *types.Response {
}
// ErrorWithCode returns an error response with the given code and message.
func ErrorWithCode(code int64, message string) *types.Response {
func ErrorWithCode(code int64) *types.Response {
return &types.Response{
Code: code,
Message: "error",
Data: nil,
}
}
// ErrorWithCodeMessage returns an error response with the given code and message.
func ErrorWithCodeMessage(code int64, message string) *types.Response {
return &types.Response{
Code: code,
Message: message,
@@ -46,3 +69,13 @@ func ErrorWithMessage(message string) *types.Response {
Data: nil,
}
}
// ErrorWithI18n returns an error response with the given message.
func ErrorWithI18n(ctx context.Context, msgId string, defaultMsg string) *types.Response {
message := i18n.FormatText(ctx, msgId, defaultMsg)
return &types.Response{
Code: 500,
Message: message,
Data: nil,
}
}