-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into emailvalidator
- Loading branch information
Showing
14 changed files
with
291 additions
and
841 deletions.
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
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 |
---|---|---|
@@ -1,18 +1,12 @@ | ||
dist: bionic | ||
language: go | ||
env: GO111MODULE=on GOFLAGS='-mod vendor' | ||
install: true | ||
email: false | ||
|
||
dist: xenial | ||
go: | ||
- 1.10 | ||
- 1.11 | ||
- 1.12 | ||
- 1.13 | ||
- tip | ||
- '1.10' | ||
- '1.11' | ||
- '1.12' | ||
- '1.13' | ||
- 'tip' | ||
|
||
before_script: | ||
- go install github.com/golangci/golangci-lint/cmd/golangci-lint | ||
script: | ||
- golangci-lint run # run a bunch of code checkers/linters in parallel | ||
- go test -v -race ./... # Run all the tests with the race detector enabled | ||
- go test -coverpkg=./... -coverprofile=coverage.info -timeout=5s | ||
- bash <(curl -s https://codecov.io/bash) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package govalidator | ||
|
||
import "testing" | ||
|
||
func BenchmarkEach(b *testing.B) { | ||
b.ResetTimer() | ||
for n := 0; n < b.N; n++ { | ||
acc := 0 | ||
data := []interface{}{1, 2, 3, 4, 5} | ||
var fn Iterator = func(value interface{}, index int) { | ||
acc = acc + value.(int) | ||
} | ||
Each(data, fn) | ||
} | ||
} | ||
|
||
func BenchmarkMap(b *testing.B) { | ||
b.ResetTimer() | ||
for n := 0; n < b.N; n++ { | ||
data := []interface{}{1, 2, 3, 4, 5} | ||
var fn ResultIterator = func(value interface{}, index int) interface{} { | ||
return value.(int) * 3 | ||
} | ||
_ = Map(data, fn) | ||
} | ||
} | ||
|
||
func BenchmarkFind(b *testing.B) { | ||
b.ResetTimer() | ||
for n := 0; n < b.N; n++ { | ||
findElement := 96 | ||
data := []interface{}{1, 2, 3, 4, findElement, 5} | ||
var fn1 ConditionIterator = func(value interface{}, index int) bool { | ||
return value.(int) == findElement | ||
} | ||
_ = Find(data, fn1) | ||
} | ||
} | ||
|
||
func BenchmarkFilter(b *testing.B) { | ||
b.ResetTimer() | ||
for n := 0; n < b.N; n++ { | ||
data := []interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} | ||
var fn ConditionIterator = func(value interface{}, index int) bool { | ||
return value.(int)%2 == 0 | ||
} | ||
_ = Filter(data, fn) | ||
} | ||
} | ||
|
||
func BenchmarkCount(b *testing.B) { | ||
b.ResetTimer() | ||
for n := 0; n < b.N; n++ { | ||
data := []interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} | ||
var fn ConditionIterator = func(value interface{}, index int) bool { | ||
return value.(int)%2 == 0 | ||
} | ||
_ = Count(data, fn) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package govalidator | ||
|
||
func ExampleFilter() { | ||
data := []interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} | ||
var fn ConditionIterator = func(value interface{}, index int) bool { | ||
return value.(int)%2 == 0 | ||
} | ||
_ = Filter(data, fn) // result = []interface{}{2, 4, 6, 8, 10} | ||
} | ||
|
||
func ExampleCount() { | ||
data := []interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} | ||
var fn ConditionIterator = func(value interface{}, index int) bool { | ||
return value.(int)%2 == 0 | ||
} | ||
_ = Count(data, fn) // result = 5 | ||
} | ||
|
||
func ExampleMap() { | ||
data := []interface{}{1, 2, 3, 4, 5} | ||
var fn ResultIterator = func(value interface{}, index int) interface{} { | ||
return value.(int) * 3 | ||
} | ||
_ = Map(data, fn) // result = []interface{}{1, 6, 9, 12, 15} | ||
} | ||
|
||
func ExampleEach() { | ||
data := []interface{}{1, 2, 3, 4, 5} | ||
var fn Iterator = func(value interface{}, index int) { | ||
println(value.(int)) | ||
} | ||
Each(data, fn) | ||
} | ||
|
||
func ExampleFind() { | ||
data := []interface{}{1, 2, 3, 4, 5} | ||
var fn ConditionIterator = func(value interface{}, index int) bool { | ||
return value.(int) == 4 | ||
} | ||
_ = Find(data, fn) // result = 4 | ||
} |
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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module github.com/asaskevich/govalidator | ||
|
||
go 1.12 | ||
go 1.13 |
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
Oops, something went wrong.