-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
48 lines (40 loc) · 1.23 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package account
import (
"strings"
)
type AccountType string
type AllAccountTypes struct {
Savings AccountType
Current AccountType
Deposit AccountType
}
func GetAllAccountTypes() *AllAccountTypes {
return &AllAccountTypes{
Savings: "Savings",
Current: "Current",
Deposit: "Deposit",
}
}
func getAllAccountTypesMap() map[string]AccountType {
return map[string]AccountType{
sanitizeAccountTypeAsString(string(accountTypes.Savings)): accountTypes.Savings,
sanitizeAccountTypeAsString(string(accountTypes.Current)): accountTypes.Current,
sanitizeAccountTypeAsString(string(accountTypes.Deposit)): accountTypes.Deposit,
}
}
var accountTypes = GetAllAccountTypes()
var accountTypesMap = getAllAccountTypesMap()
func GetAccountType(accountTypeAsString string) *AccountType {
stringSanitized := sanitizeAccountTypeAsString(accountTypeAsString)
accountType, exists := accountTypesMap[stringSanitized]
if exists {
return &accountType
}
return nil
}
func sanitizeAccountTypeAsString(asString string) string {
cleanedAccountType := strings.ToLower(asString)
cleanedAccountType = strings.ReplaceAll(cleanedAccountType, "account", "")
cleanedAccountType = strings.ReplaceAll(cleanedAccountType, " ", "")
return cleanedAccountType
}