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

fix: custom provider generator #43

Merged
merged 6 commits into from
Jan 13, 2019
Merged

fix: custom provider generator #43

merged 6 commits into from
Jan 13, 2019

Conversation

bxcodec
Copy link
Owner

@bxcodec bxcodec commented Jan 13, 2019

Proposed changes:
Now we can easily add our own custom faker-generator provider.
Example:

type Gondoruwo struct {
	Name       string
	Locatadata int
}

func CustomGenerator() {
	faker.AddProvider("customIdFaker", func(v reflect.Value) (interface{}, error) {
		 return int64(43), nil
	})
	faker.AddProvider("danger", func(v reflect.Value) (interface{}, error) {
		return "danger-ranger", nil
	})

	faker.AddProvider("gondoruwo", func(v reflect.Value) (interface{}, error) {
		obj := Gondoruwo{
			Name:       "Power",
			Locatadata: 324,
		}
		return obj, nil
	})
}

type Sample struct {
	ID                 int64     `faker:"customIdFaker"`
	Gondoruwo          Gondoruwo `faker:"gondoruwo"`
	Danger             string    `faker:"danger"`
}

Results:

{ID:43 Gondoruwo:{Name:Power Locatadata:324} Danger:danger-ranger}

@bxcodec bxcodec changed the title fix: custom provider generator (test-file is not updated yet) fix: custom provider generator Jan 13, 2019
@codecov
Copy link

codecov bot commented Jan 13, 2019

Codecov Report

Merging #43 into master will decrease coverage by 2.09%.
The diff coverage is 93.97%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #43     +/-   ##
=========================================
- Coverage   98.12%   96.03%   -2.1%     
=========================================
  Files          10       10             
  Lines         426      529    +103     
=========================================
+ Hits          418      508     +90     
- Misses          4       11      +7     
- Partials        4       10      +6
Impacted Files Coverage Δ
datetime.go 100% <100%> (ø) ⬆️
uuid.go 100% <100%> (ø) ⬆️
phone.go 100% <100%> (ø) ⬆️
price.go 100% <100%> (ø) ⬆️
payment.go 100% <100%> (ø) ⬆️
address.go 100% <100%> (ø) ⬆️
person.go 97.36% <100%> (-2.64%) ⬇️
internet.go 100% <100%> (ø) ⬆️
lorem.go 100% <100%> (ø) ⬆️
faker.go 89.58% <50%> (-5.88%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 36687d3...8d234df. Read the comment docs.

@bxcodec bxcodec merged commit 99d982f into master Jan 13, 2019
@bxcodec bxcodec deleted the fixCustomPrviderWithTag branch January 13, 2019 13:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant