mirror of
https://github.com/volatiletech/authboss.git
synced 2026-06-19 23:00:27 +02:00
Lowercase all identifiers used with storer.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
)
|
||||
@@ -110,6 +111,9 @@ func (a Attributes) Bind(strct interface{}) error {
|
||||
structVal := reflect.ValueOf(strct).Elem()
|
||||
structType = structVal.Type()
|
||||
for k, v := range a {
|
||||
|
||||
k = strings.Title(k)
|
||||
|
||||
if _, has := structType.FieldByName(k); !has {
|
||||
return fmt.Errorf("Bind: Struct was missing %s field, type: %v", k, reflect.TypeOf(v).String())
|
||||
}
|
||||
@@ -161,6 +165,8 @@ func Unbind(intf interface{}) Attributes {
|
||||
continue // Unexported
|
||||
}
|
||||
|
||||
name = strings.ToLower(name)
|
||||
|
||||
switch field.Kind() {
|
||||
case reflect.Struct:
|
||||
if field.Type() == dateTimeType {
|
||||
|
||||
+6
-6
@@ -73,21 +73,21 @@ func TestAttributes_BindTypeFail(t *testing.T) {
|
||||
ToBind interface{}
|
||||
}{
|
||||
{
|
||||
Attr: Attributes{"Integer": 5},
|
||||
Attr: Attributes{"integer": 5},
|
||||
Err: "should be int",
|
||||
ToBind: &struct {
|
||||
Integer string
|
||||
}{},
|
||||
},
|
||||
{
|
||||
Attr: Attributes{"String": ""},
|
||||
Attr: Attributes{"string": ""},
|
||||
Err: "should be string",
|
||||
ToBind: &struct {
|
||||
String int
|
||||
}{},
|
||||
},
|
||||
{
|
||||
Attr: Attributes{"Date": time.Time{}},
|
||||
Attr: Attributes{"date": time.Time{}},
|
||||
Err: "should be time.Time",
|
||||
ToBind: &struct {
|
||||
Date int
|
||||
@@ -122,7 +122,7 @@ func TestAttributes_Unbind(t *testing.T) {
|
||||
t.Error("Expected three fields, got:", len(attr))
|
||||
}
|
||||
|
||||
if v, ok := attr["Integer"]; !ok {
|
||||
if v, ok := attr["integer"]; !ok {
|
||||
t.Error("Could not find Integer entry.")
|
||||
} else if val, ok := v.(int); !ok {
|
||||
t.Errorf("Underlying type is wrong: %T", v)
|
||||
@@ -130,7 +130,7 @@ func TestAttributes_Unbind(t *testing.T) {
|
||||
t.Error("Underlying value is wrong:", val)
|
||||
}
|
||||
|
||||
if v, ok := attr["String"]; !ok {
|
||||
if v, ok := attr["string"]; !ok {
|
||||
t.Error("Could not find String entry.")
|
||||
} else if val, ok := v.(string); !ok {
|
||||
t.Errorf("Underlying type is wrong: %T", v)
|
||||
@@ -138,7 +138,7 @@ func TestAttributes_Unbind(t *testing.T) {
|
||||
t.Error("Underlying value is wrong:", val)
|
||||
}
|
||||
|
||||
if v, ok := attr["Time"]; !ok {
|
||||
if v, ok := attr["time"]; !ok {
|
||||
t.Error("Could not find Time entry.")
|
||||
} else if val, ok := v.(time.Time); !ok {
|
||||
t.Errorf("Underlying type is wrong: %T", v)
|
||||
|
||||
Reference in New Issue
Block a user