Skip to content

Commit 6f0703a

Browse files
chore(ci): Adding github actions pipeline (#2)
* chore(ci): Adding github actions pipeline * chore: Fixing go fmt * chore: Tweaking coverage * chore: Don't test on windows or mac * chore: Tweas
1 parent dbc8262 commit 6f0703a

File tree

5 files changed

+63
-32
lines changed

5 files changed

+63
-32
lines changed

.github/workflows/main.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
name: Test
12+
strategy:
13+
matrix:
14+
go: ['oldstable', 'stable']
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Set up Golang
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version: '${{ matrix.go }}'
21+
22+
- name: Checkout code
23+
uses: actions/checkout@v2
24+
25+
- name: Test
26+
run: |
27+
test -z "`gofmt -l -d .`"
28+
test -z "`go run golang.org/x/lint/golint@latest ./...`"
29+
go test -v --race -covermode=atomic -coverprofile=coverage.out

date.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ type DateRule struct {
2525
// Date returns a validation rule that checks if a string value is in a format that can be parsed into a date.
2626
// The format of the date should be specified as the layout parameter which accepts the same value as that for time.Parse.
2727
// For example,
28-
// validation.Date(time.ANSIC)
29-
// validation.Date("02 Jan 06 15:04 MST")
30-
// validation.Date("2006-01-02")
28+
//
29+
// validation.Date(time.ANSIC)
30+
// validation.Date("02 Jan 06 15:04 MST")
31+
// validation.Date("2006-01-02")
3132
//
3233
// By calling Min() and/or Max(), you can let the Date rule to check if a parsed date value is within
3334
// the specified date range.

map.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ type (
4141
// Use Key() to specify map keys that need to be validated. Each Key() call specifies a single key which can
4242
// be associated with multiple rules.
4343
// For example,
44-
// validation.Map(
45-
// validation.Key("Name", validation.Required),
46-
// validation.Key("Value", validation.Required, validation.Length(5, 10)),
47-
// )
44+
//
45+
// validation.Map(
46+
// validation.Key("Name", validation.Required),
47+
// validation.Key("Value", validation.Required, validation.Length(5, 10)),
48+
// )
4849
//
4950
// A nil value is considered valid. Use the Required rule to make sure a map value is present.
5051
func Map(keys ...*KeyRules) MapRule {

struct.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ func (e ErrFieldNotFound) Error() string {
4747
// should be specified as a pointer to the field. A field can be associated with multiple rules.
4848
// For example,
4949
//
50-
// value := struct {
51-
// Name string
52-
// Value string
53-
// }{"name", "demo"}
54-
// err := validation.ValidateStruct(&value,
55-
// validation.Field(&a.Name, validation.Required),
56-
// validation.Field(&a.Value, validation.Required, validation.Length(5, 10)),
57-
// )
58-
// fmt.Println(err)
59-
// // Value: the length must be between 5 and 10.
50+
// value := struct {
51+
// Name string
52+
// Value string
53+
// }{"name", "demo"}
54+
// err := validation.ValidateStruct(&value,
55+
// validation.Field(&a.Name, validation.Required),
56+
// validation.Field(&a.Value, validation.Required, validation.Length(5, 10)),
57+
// )
58+
// fmt.Println(err)
59+
// // Value: the length must be between 5 and 10.
6060
//
6161
// An error will be returned if validation fails.
6262
func ValidateStruct(structPtr interface{}, fields ...*FieldRules) error {

validation.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ var (
6060
// Validate validates the given value and returns the validation error, if any.
6161
//
6262
// Validate performs validation using the following steps:
63-
// 1. For each rule, call its `Validate()` to validate the value. Return if any error is found.
64-
// 2. If the value being validated implements `Validatable`, call the value's `Validate()`.
65-
// Return with the validation result.
66-
// 3. If the value being validated is a map/slice/array, and the element type implements `Validatable`,
67-
// for each element call the element value's `Validate()`. Return with the validation result.
63+
// 1. For each rule, call its `Validate()` to validate the value. Return if any error is found.
64+
// 2. If the value being validated implements `Validatable`, call the value's `Validate()`.
65+
// Return with the validation result.
66+
// 3. If the value being validated is a map/slice/array, and the element type implements `Validatable`,
67+
// for each element call the element value's `Validate()`. Return with the validation result.
6868
func Validate(value interface{}, rules ...Rule) error {
6969
for _, rule := range rules {
7070
if s, ok := rule.(skipRule); ok && s.skip {
@@ -103,16 +103,16 @@ func Validate(value interface{}, rules ...Rule) error {
103103
// ValidateWithContext validates the given value with the given context and returns the validation error, if any.
104104
//
105105
// ValidateWithContext performs validation using the following steps:
106-
// 1. For each rule, call its `ValidateWithContext()` to validate the value if the rule implements `RuleWithContext`.
107-
// Otherwise call `Validate()` of the rule. Return if any error is found.
108-
// 2. If the value being validated implements `ValidatableWithContext`, call the value's `ValidateWithContext()`
109-
// and return with the validation result.
110-
// 3. If the value being validated implements `Validatable`, call the value's `Validate()`
111-
// and return with the validation result.
112-
// 4. If the value being validated is a map/slice/array, and the element type implements `ValidatableWithContext`,
113-
// for each element call the element value's `ValidateWithContext()`. Return with the validation result.
114-
// 5. If the value being validated is a map/slice/array, and the element type implements `Validatable`,
115-
// for each element call the element value's `Validate()`. Return with the validation result.
106+
// 1. For each rule, call its `ValidateWithContext()` to validate the value if the rule implements `RuleWithContext`.
107+
// Otherwise call `Validate()` of the rule. Return if any error is found.
108+
// 2. If the value being validated implements `ValidatableWithContext`, call the value's `ValidateWithContext()`
109+
// and return with the validation result.
110+
// 3. If the value being validated implements `Validatable`, call the value's `Validate()`
111+
// and return with the validation result.
112+
// 4. If the value being validated is a map/slice/array, and the element type implements `ValidatableWithContext`,
113+
// for each element call the element value's `ValidateWithContext()`. Return with the validation result.
114+
// 5. If the value being validated is a map/slice/array, and the element type implements `Validatable`,
115+
// for each element call the element value's `Validate()`. Return with the validation result.
116116
func ValidateWithContext(ctx context.Context, value interface{}, rules ...Rule) error {
117117
for _, rule := range rules {
118118
if s, ok := rule.(skipRule); ok && s.skip {

0 commit comments

Comments
 (0)