Skip to content

Commit

Permalink
Changed structure for module version
Browse files Browse the repository at this point in the history
  • Loading branch information
guiferpa committed Nov 30, 2020
1 parent 75cfbf6 commit b12bd3f
Show file tree
Hide file tree
Showing 38 changed files with 31 additions and 1,636 deletions.
4 changes: 2 additions & 2 deletions examples/custom_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"log"

"github.com/guiferpa/gody"
"github.com/guiferpa/gody/rule"
gody "github.com/guiferpa/gody/v2"
"github.com/guiferpa/gody/v2/rule"
)

// ErrInvalidPalindrome is a custom error to a specific rule implementation
Expand Down
2 changes: 1 addition & 1 deletion examples/http_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"strconv"

"github.com/guiferpa/gody"
gody "github.com/guiferpa/gody/v2"
)

type ErrIsAdult struct{}
Expand Down
4 changes: 2 additions & 2 deletions examples/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"log"

"github.com/guiferpa/gody"
"github.com/guiferpa/gody/rule"
gody "github.com/guiferpa/gody/v2"
"github.com/guiferpa/gody/v2/rule"
)

func SimpleDefaultValidation() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/guiferpa/gody
module github.com/guiferpa/gody/v2

go 1.13
3 changes: 3 additions & 0 deletions serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func RawSerialize(tn string, b interface{}) ([]Field, error) {

fieldValue := valueOf.FieldByName(field.Name)
fieldNameToLower := strings.ToLower(field.Name)
if fieldNameFromJSONTag := field.Tag.Get("json"); fieldNameFromJSONTag != "" {
fieldNameToLower = fieldNameFromJSONTag
}
if kindOfField := field.Type.Kind(); kindOfField == reflect.Struct {
if fieldConverted := fieldValue.Convert(fieldValue.Type()); fieldConverted.CanInterface() {
payload := fieldConverted.Interface()
Expand Down
19 changes: 19 additions & 0 deletions serialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,25 @@ func TestRawSerializeWithEmptyTagName(t *testing.T) {
}
}

func TestRawSerializeWithJSONTagName(t *testing.T) {
body := struct {
A string `json:"b" validate:"not_empty"`
}{}

fields, err := RawSerialize("validate", body)
if err != nil {
t.Error(err)
return
}

field := fields[0]

if got, want := field.Name, "b"; got != want {
t.Errorf("Unexpected field name, got: %s, want: %s", got, want)
return
}
}

func BenchmarkSerializeBodyStruct(b *testing.B) {
b.ResetTimer()
body := map[string]string{"test-key": "test-value"}
Expand Down
61 changes: 0 additions & 61 deletions v2/examples/custom_rule.go

This file was deleted.

107 changes: 0 additions & 107 deletions v2/examples/http_api.go

This file was deleted.

75 changes: 0 additions & 75 deletions v2/examples/simple.go

This file was deleted.

5 changes: 0 additions & 5 deletions v2/go.mod

This file was deleted.

2 changes: 0 additions & 2 deletions v2/go.sum

This file was deleted.

7 changes: 0 additions & 7 deletions v2/rule.go

This file was deleted.

36 changes: 0 additions & 36 deletions v2/rule/enum.go

This file was deleted.

Loading

0 comments on commit b12bd3f

Please sign in to comment.