This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 147
fix slice tag bug AND add chinese name #141
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4a59886
fix slice len and slice_len
qiangmzsx d07ac82
stop min
qiangmzsx 832928b
fix len test
qiangmzsx 129ae16
add chinese name
qiangmzsx 2008b46
add chinese name
qiangmzsx fc8862a
Set tag priority
qiangmzsx 5032f03
add chinese_first_name,chinese_last_name and chinese_name
qiangmzsx a16b406
Merge branch 'master' into master
bxcodec 101b50a
fix test fun
qiangmzsx e5e3553
Merge remote-tracking branch 'upstream/master'
qiangmzsx c75b4b7
Merge branch 'master' of https://github.com/qiangmzsx/faker
qiangmzsx aad6414
fix golangci-lint error
qiangmzsx 282b75b
fix golint and test error
qiangmzsx ae107e2
fix golangci-lint error
qiangmzsx 8a32752
Merge branch 'master' into master
bxcodec 95590e0
Merge branch 'master' into master
bxcodec d73486f
Fix merge redundant code
qiangmzsx 1224606
Merge branch 'master' of https://github.com/qiangmzsx/faker
qiangmzsx 7c6b13c
fix faker test
qiangmzsx 477c501
Resolve code conflicts
qiangmzsx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,9 @@ const ( | |
FirstNameFemaleTag = "first_name_female" | ||
LastNameTag = "last_name" | ||
NAME = "name" | ||
ChineseFirstNameTag = "chinese_first_name" | ||
ChineseLastNameTag = "chinese_last_name" | ||
ChineseNameTag = "chinese_name" | ||
GENDER = "gender" | ||
UnixTimeTag = "unix_time" | ||
DATE = "date" | ||
|
@@ -134,6 +137,15 @@ const ( | |
//hyphen = "-" | ||
) | ||
|
||
// PriorityTags define the priority order of the tag | ||
var PriorityTags = []string{ID, HyphenatedID, EmailTag, MacAddressTag, DomainNameTag, UserNameTag, URLTag, IPV4Tag, | ||
IPV6Tag, PASSWORD, JWT, LATITUDE, LONGITUDE, CreditCardNumber, CreditCardType, PhoneNumber, TollFreeNumber, | ||
E164PhoneNumberTag, TitleMaleTag, TitleFemaleTag, FirstNameTag, FirstNameMaleTag, FirstNameFemaleTag, LastNameTag, | ||
NAME, ChineseFirstNameTag, ChineseLastNameTag, ChineseNameTag, GENDER, UnixTimeTag, DATE, TIME, MonthNameTag, | ||
YEAR, DayOfWeekTag, DayOfMonthTag, TIMESTAMP, CENTURY, TIMEZONE, TimePeriodTag, WORD, SENTENCE, PARAGRAPH, | ||
CurrencyTag, AmountTag, AmountWithCurrencyTag, SKIP, Length, SliceLength, Language, BoundaryStart, BoundaryEnd, ONEOF, | ||
} | ||
|
||
var defaultTag = map[string]string{ | ||
EmailTag: EmailTag, | ||
MacAddressTag: MacAddressTag, | ||
|
@@ -158,6 +170,9 @@ var defaultTag = map[string]string{ | |
FirstNameFemaleTag: FirstNameFemaleTag, | ||
LastNameTag: LastNameTag, | ||
NAME: NAME, | ||
ChineseFirstNameTag: ChineseFirstNameTag, | ||
ChineseLastNameTag: ChineseLastNameTag, | ||
ChineseNameTag: ChineseNameTag, | ||
GENDER: GENDER, | ||
UnixTimeTag: UnixTimeTag, | ||
DATE: DATE, | ||
|
@@ -208,6 +223,9 @@ var mapperTag = map[string]TaggedFunction{ | |
FirstNameFemaleTag: GetPerson().FirstNameFemale, | ||
LastNameTag: GetPerson().LastName, | ||
NAME: GetPerson().Name, | ||
ChineseFirstNameTag: GetPerson().ChineseFirstName, | ||
ChineseLastNameTag: GetPerson().ChineseLastName, | ||
ChineseNameTag: GetPerson().ChineseName, | ||
GENDER: GetPerson().Gender, | ||
UnixTimeTag: GetDateTimer().UnixTime, | ||
DATE: GetDateTimer().Date, | ||
|
@@ -422,7 +440,7 @@ func AddProvider(tag string, provider TaggedFunction) error { | |
if _, ok := mapperTag[tag]; ok { | ||
return errors.New(ErrTagAlreadyExists) | ||
} | ||
|
||
PriorityTags = append(PriorityTags, tag) | ||
mapperTag[tag] = provider | ||
|
||
return nil | ||
|
@@ -640,11 +658,13 @@ func isZero(field reflect.Value) (bool, error) { | |
} | ||
|
||
func decodeTags(typ reflect.Type, i int) structTag { | ||
tags := strings.Split(typ.Field(i).Tag.Get(tagName), ",") | ||
tagField := typ.Field(i).Tag.Get(tagName) | ||
tags := strings.Split(tagField, ",") | ||
|
||
keepOriginal := false | ||
uni := false | ||
res := make([]string, 0) | ||
pMap := make(map[string]string) | ||
for _, tag := range tags { | ||
if tag == keep { | ||
keepOriginal = true | ||
|
@@ -653,7 +673,28 @@ func decodeTags(typ reflect.Type, i int) structTag { | |
uni = true | ||
continue | ||
} | ||
res = append(res, tag) | ||
// res = append(res, tag) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove if not used anymore |
||
ptag := strings.ToLower(strings.Trim(strings.Split(tag, "=")[0], " ")) | ||
pMap[ptag] = tag | ||
ptag = strings.ToLower(strings.Trim(strings.Split(tag, ":")[0], " ")) | ||
pMap[ptag] = tag | ||
} | ||
// Priority | ||
for _, ptag := range PriorityTags { | ||
if tag, ok := pMap[ptag]; ok { | ||
if ptag == ONEOF { | ||
res = append(res, tags...) | ||
} else { | ||
res = append(res, tag) | ||
} | ||
delete(pMap, ptag) | ||
} | ||
} | ||
// custom,keep,unique | ||
if len(res) < 1 { | ||
if !keepOriginal && !uni { | ||
res = append(res, tags...) | ||
} | ||
} | ||
|
||
return structTag{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remind me again, what are these priority tags used for?