structure: golint and govet improvements

This commit is contained in:
Fatih Arslan 2014-08-08 15:38:40 +03:00
parent 091a0feb9b
commit 50c639fd56
2 changed files with 13 additions and 9 deletions

View File

@ -4,6 +4,9 @@ package structure
import "reflect"
var (
// DefaultTagName is the default tag name for struct fields which provides
// a more granular to tweak certain structs. Lookup the necessary functions
// for more info.
DefaultTagName = "structure" // struct's field default tag name
)
@ -80,7 +83,7 @@ func Map(s interface{}) map[string]interface{} {
func Values(s interface{}) []interface{} {
v, fields := strctInfo(s)
t := make([]interface{}, 0)
var t []interface{}
for _, field := range fields {
val := v.FieldByName(field.Name)
@ -120,7 +123,8 @@ func Values(s interface{}) []interface{} {
func Fields(s interface{}) []string {
v, fields := strctInfo(s)
keys := make([]string, 0)
var keys []string
for _, field := range fields {
val := v.FieldByName(field.Name)
@ -290,7 +294,7 @@ func strctInfo(s interface{}) (reflect.Value, []reflect.StructField) {
v := strctVal(s)
t := v.Type()
f := make([]reflect.StructField, 0)
var f []reflect.StructField
for i := 0; i < t.NumField(); i++ {
field := t.Field(i)

View File

@ -200,7 +200,7 @@ func TestMap_Nested(t *testing.T) {
}
if name := in["Name"].(string); name != "example" {
t.Error("Map nested struct's name field should give example, got: %s", name)
t.Errorf("Map nested struct's name field should give example, got: %s", name)
}
}
@ -228,7 +228,7 @@ func TestMap_Anonymous(t *testing.T) {
}
if name := in["Name"].(string); name != "example" {
t.Error("Embedded A struct's Name field should give example, got: %s", name)
t.Errorf("Embedded A struct's Name field should give example, got: %s", name)
}
}
@ -771,13 +771,13 @@ func TestName(t *testing.T) {
n := Name(f)
if n != "Foo" {
t.Error("Name should return Foo, got: %s", n)
t.Errorf("Name should return Foo, got: %s", n)
}
unnamed := struct{ Name string }{Name: "Cihangir"}
m := Name(unnamed)
if m != "" {
t.Error("Name should return empty string for unnamed struct, got: %s", n)
t.Errorf("Name should return empty string for unnamed struct, got: %s", n)
}
defer func() {