-
Notifications
You must be signed in to change notification settings - Fork 65
Description
Use Cases:
-
I have a validator that performs validation when a user submits information. The validation method is similar to
v.In(arrary), and I need to obtain an array of enumeration values for validation.
current:v.In([]enum.UserStatus{enum.UserStatusDisabled, enum.UserStatusBanned, enum.UserStatusNormal,})
Implementation: Add aGetRecords(or other name) method that returns an array of enumeration values. -
In my application, users have several statuses (user_status: disabled, banned, normal). Users in other statuses except normal are prohibited from logging in. When they log in, I can only return "disabled" or "banned." However, because I'm in a non-English speaking country, these aren't sufficient to describe the reason.
I'd like to add corresponding descriptive information for each enumeration value. When a user enters a certain status, I can retrieve the corresponding description and provide it to the user.
Implementation:
a. Allow the use of - to add description information when defining.
example
// ENUM(disabled - The account has been disabled, banned - This account has been disabled for security reasons, normal)
type UserStatus stringThe - and the description following it are optional. If present, parse it and add a Map and the methods described below. Otherwise, maintain the current logic.
b. Add a GetDescription (or other name) method to return the description of the enumeration value.
var _UserStatusValueDescription = map[string]string{
"disabled": "The account has been disabled",
"banned": "This account has been disabled for security reasons",
"normal": "",
}
func (x DocumentStatus) GetDescription() string {
description, _ := _UserStatusValueDescription[x]
return description
}If you think these requirements are reasonable, I'd be happy to implement them.