Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
privating the credit card func
Browse files Browse the repository at this point in the history
  • Loading branch information
bxcodec committed Jul 12, 2017
1 parent 7d6f36f commit 47a2ad3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions credit_card.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ const (
)

var creditCards = map[string]creditCard{
"VISA": {"VISA", 16, []int{4539, 4556, 4916, 4532, 4929, 40240071, 4485, 4716, 4}},
"MasterCard": {"MasterCard", 16, []int{51, 52, 53, 54, 55}},
"American Express": {"American Express", 15, []int{34, 37}},
"Discover": {"Discover", 16, []int{6011}},
"visa": {"VISA", 16, []int{4539, 4556, 4916, 4532, 4929, 40240071, 4485, 4716, 4}},
"mastercard": {"MasterCard", 16, []int{51, 52, 53, 54, 55}},
"american express": {"American Express", 15, []int{34, 37}},
"discover": {"Discover", 16, []int{6011}},
}

// CreditCardType returns one of the following credit values:
// VISA, MasterCard, American Express and Discover
var cacheCreditCard string

func CreditCardType() string {
func creditCardType() string {
n := len(creditCards)
r := rand.New(src)
if cacheCreditCard != "" {
Expand All @@ -43,15 +43,15 @@ func CreditCardType() string {
}

// CreditCardNum generated credit card number according to the card number rules
func CreditCardNum(ccType string) string {
func creditCardNum(ccType string) string {
r := rand.New(src)
if ccType != "" {
ccType = strings.ToLower(ccType)
cacheCreditCard = ccType
} else if cacheCreditCard != "" {
ccType = cacheCreditCard
ccType = strings.ToLower(cacheCreditCard)
} else {

ccType = strings.ToLower(CreditCardType())
ccType = strings.ToLower(creditCardType())
cacheCreditCard = ccType
}
card := creditCards[ccType]
Expand Down
4 changes: 2 additions & 2 deletions faker.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ func userDefinedString(v reflect.Value, tag string) error {
val = ipv6()
case CREDIT_CARD_NUMBER:

val = CreditCardNum("")
val = creditCardNum("")

case CREDIT_CARD_TYPE:

val = CreditCardType()
val = creditCardType()

}
v.SetString(val)
Expand Down
2 changes: 1 addition & 1 deletion faker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ type CStruct struct {
type TaggedStruct struct {
Latitude float32 `faker:"lat"`
Long float32 `faker:"long"`
CreditCardType string `faker:"cc_type"`
CreditCardNumber string `faker:"cc_number"`
CreditCardType string `faker:"cc_type"`
Email string `faker:"email"`
IPV4 string `faker:"ipv4"`
IPV6 string `faker:"ipv6"`
Expand Down

0 comments on commit 47a2ad3

Please sign in to comment.