Documentation
¶
Index ¶
- Variables
- func CheckParametersLost(params map[string]string, paramNames ...string) models.Result[any]
- func Close()
- func Error(code int, messageId string) models.Result[any]
- func ErrorDef(def errcode.Definition, args ...any) models.Result[any]
- func ErrorDefT[T any](def errcode.Definition, args ...any) models.Result[T]
- func ErrorT[T any](code int, messageId string) models.Result[T]
- func ErrorWithMsg(code int, messageId, msg string) models.Result[any]
- func ErrorWithMsgT[T any](code int, messageId, msg string) models.Result[T]
- func Format(messageId string, args ...any) string
- func GetString(messageID, language string) string
- func GetXLangString(messageID, language string) string
- func Init() error
- func ParamError(param string) models.Result[any]
- func ParamLostError(param string) models.Result[any]
- func RouterGroup(group *gin.RouterGroup)
- func String(messageId string) string
- func Success[T any](data T) models.Result[T]
- func SuccessWithPage[T any](data T, count, index, size, total int) models.Result[T]
- type Entry
- type ListOptions
- type Store
- func (s *Store) Create(ctx context.Context, entry *Entry) error
- func (s *Store) Delete(ctx context.Context, messageID, language string) error
- func (s *Store) Get(ctx context.Context, messageID, language string) (*Entry, error)
- func (s *Store) List(ctx context.Context, options ListOptions) ([]Entry, int64, error)
- func (s *Store) TableName() string
- func (s *Store) Translate(ctx context.Context, messageID, language string) (string, error)
- func (s *Store) Update(ctx context.Context, entry *Entry) error
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func CheckParametersLost ¶
func ErrorDef ¶
ErrorDef v2.1 新增:基于 errcode.Definition 的标准化错误响应。
把三向映射(errcode.Definition → i18n 文案 → HTTP 状态码)一步完成:
- 文案通过 def.MessageKey + args 走 i18n.Format
- 业务码写入返回体的 Code 字段
- HTTP 状态码由 def.HTTPStatus 决定(调用方需在自己的 handler 里手动 c.JSON(def.HTTPStatus, result))
返回的 result 是已渲染文案的 models.Result,业务侧调用方式:
c.JSON(errcode.LookupDef(errcode.PARAM_ERROR).HTTPStatus,
i18n.ErrorDef(errcode.PARAM_ERROR, paramName))
func GetString ¶ added in v2.0.12
GetString resolves a message from the built-in dictionary with language fallback.
func GetXLangString ¶
GetXLangString is kept for source compatibility and uses the local dictionary. Deprecated: use GetString.
func Init ¶
func Init() error
Init initializes the built-in database dictionary; no external service is used.
func RouterGroup ¶ added in v2.0.12
func RouterGroup(group *gin.RouterGroup)
RouterGroup mounts dictionary CRUD on a caller-supplied group. GET /list lists entries; GET /get and POST /delete use messageId/language query parameters; POST /save and POST /update accept {"messageId":"hello","language":"en","text":"Hello"}.
Types ¶
type Entry ¶ added in v2.0.12
type Entry struct {
MessageID string `json:"messageId" gorm:"column:message_id;size:191;primaryKey;autoIncrement:false"`
Language string `json:"language" gorm:"size:35;primaryKey;autoIncrement:false"`
Text string `json:"text" gorm:"type:text;not null"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Entry stores one translation. A message can have one entry per language.
type ListOptions ¶ added in v2.0.12
type Store ¶ added in v2.0.12
type Store struct {
// contains filtered or unexported fields
}
Store uses the application's relational connection, or owns a fallback SQLite connection.
func NewStore ¶ added in v2.0.12
NewStore creates the dictionary table on an existing GORM connection. The caller retains ownership of the connection.