validator

package
v0.0.0-...-6819526 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default *validator.Validate
View Source
var LanguageCtxKey = "language"

Functions

func Init

func Init(multipleTrans ...TranslationLanguage)

Init 初始化翻译器 默认支持 en-英文和 zh-中文、zh_Hant_TW-繁体 multipleTrans 支持其他国家或地区翻译器

func Struct

func Struct(obj any) error

func StructCtx

func StructCtx(ctx context.Context, obj any) error

func TransErr

func TransErr(err error) error

func TransErrCtx

func TransErrCtx(ctx context.Context, err error) error

func TransErrLocale

func TransErrLocale(locale string, err error) error

func TransErrZh

func TransErrZh(err error) error

Types

type GetRequestLanguageFunc

type GetRequestLanguageFunc func(ctx context.Context) string
var DefaultGetLanguage GetRequestLanguageFunc = func(ctx context.Context) string {
	lang, _ := ctx.Value(LanguageCtxKey).(string)
	if lang == "" {
		lang = "en"
	}
	return lang
}

type TranslationLanguage

type TranslationLanguage struct {
	Lt           locales.Translator
	RegisterFunc func(*validator.Validate, ut.Translator) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL