From 993d6e3076f23abbc0ee4178ac0b5d4732355f98 Mon Sep 17 00:00:00 2001 From: john Date: Sun, 10 May 2020 10:56:11 +0800 Subject: [PATCH] improve package gvalid --- i18n/gi18n/gi18n.go | 9 +- i18n/gi18n/gi18n_instance.go | 3 +- i18n/gi18n/gi18n_manager.go | 131 ++++--- util/gvalid/gvalid_check.go | 514 ++++++------------------- util/gvalid/gvalid_message.go | 76 ++-- util/gvalid/gvalid_rule_length.go | 80 ++++ util/gvalid/gvalid_rule_luhn.go | 28 ++ util/gvalid/gvalid_rule_range.go | 86 +++++ util/gvalid/gvalid_rule_required.go | 108 ++++++ util/gvalid/gvalid_rule_resident_id.go | 58 +++ 10 files changed, 620 insertions(+), 473 deletions(-) create mode 100644 util/gvalid/gvalid_rule_length.go create mode 100644 util/gvalid/gvalid_rule_luhn.go create mode 100644 util/gvalid/gvalid_rule_range.go create mode 100644 util/gvalid/gvalid_rule_required.go create mode 100644 util/gvalid/gvalid_rule_resident_id.go diff --git a/i18n/gi18n/gi18n.go b/i18n/gi18n/gi18n.go index 28e807542..3fdf3d23d 100644 --- a/i18n/gi18n/gi18n.go +++ b/i18n/gi18n/gi18n.go @@ -8,6 +8,7 @@ package gi18n var ( + // defaultManager is the default i18n instance for package functions. defaultManager = Instance() ) @@ -26,7 +27,7 @@ func SetDelimiters(left, right string) { defaultManager.SetDelimiters(left, right) } -// T is alias of Translate. +// T is alias of Translate for convenience. func T(content string, language ...string) string { return defaultManager.T(content, language...) } @@ -36,3 +37,9 @@ func T(content string, language ...string) string { func Translate(content string, language ...string) string { return defaultManager.Translate(content, language...) } + +// GetValue retrieves and returns the configured content for given key and specified language. +// It returns an empty string if not found. +func GetContent(key string, language ...string) string { + return defaultManager.GetContent(key, language...) +} diff --git a/i18n/gi18n/gi18n_instance.go b/i18n/gi18n/gi18n_instance.go index a014046b1..61ab91257 100644 --- a/i18n/gi18n/gi18n_instance.go +++ b/i18n/gi18n/gi18n_instance.go @@ -14,7 +14,8 @@ const ( ) var ( - // Instances map. + // instances is the instances map for management + // for multiple i18n instance by name. instances = gmap.NewStrAnyMap(true) ) diff --git a/i18n/gi18n/gi18n_manager.go b/i18n/gi18n/gi18n_manager.go index 277e874e4..a4efc6269 100644 --- a/i18n/gi18n/gi18n_manager.go +++ b/i18n/gi18n/gi18n_manager.go @@ -43,11 +43,13 @@ type Options struct { } var ( - // defaultDelimiters defines the key variable delimiters. + // defaultDelimiters defines the default key variable delimiters. defaultDelimiters = []string{"{#", "}"} ) // New creates and returns a new i18n manager. +// The optional parameter