Skip to content

Commit

Permalink
feat: defaulting query parameter keys to lowercase names (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
noxecane authored Oct 12, 2020
1 parent 7ea112c commit e8980cc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/http"
"reflect"
"strconv"
"strings"

"github.com/pkg/errors"
)
Expand All @@ -16,6 +17,7 @@ import (
// - float(all bit sizes)
// - string
// - ISO8601 time
// It defaults the keys to the lowercase struct field names.
func ParseQuery(query map[string]string, v interface{}) error {
result := reflect.ValueOf(v).Elem()
resultType := result.Type()
Expand All @@ -34,7 +36,7 @@ func ParseQuery(query map[string]string, v interface{}) error {
// get query parameter name
key := field.Tag.Get("key")
if key == "" {
key = field.Name
key = strings.ToLower(field.Name)
}

// for fields with default values
Expand Down
6 changes: 3 additions & 3 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (

func TestParseQuery(t *testing.T) {
type mapStruct struct {
Name string `key:"name"`
Age int32 `key:"age" default:"30"`
Limit *int `key:"limit"`
Name string
Limit *int
Age int32 `default:"30"`
CreatedAt *time.Time `key:"date"`
}

Expand Down
2 changes: 1 addition & 1 deletion sealbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestEncryptDecrypt(t *testing.T) {
})

t.Run("Decrypt for normal strings", func(t *testing.T) {
someString := faker.Lorem().Characters(16)
someString := faker.Lorem().Characters(64)

_, err := Decrypt(secret, someString)
if err == nil {
Expand Down

0 comments on commit e8980cc

Please sign in to comment.