Skip to content

Commit

Permalink
Removing Headers() method from Schema. Updating example to deal with …
Browse files Browse the repository at this point in the history
…Schema fields. #16
  • Loading branch information
danielfireman committed Sep 13, 2017
1 parent 71122da commit 9997dad
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 26 deletions.
7 changes: 5 additions & 2 deletions examples/validate/main.go
Expand Up @@ -19,8 +19,11 @@ func main() {
log.Fatal(err)
}

// Printing headers.
log.Printf("Headers: %v\n", capitalSchema.Headers())
// Printing schema fields names.
log.Println("Fields:")
for i, f := range capitalSchema.Fields {
log.Printf("%d - %s\n", i, f.Name)
}

// Working with schema fields.
if capitalSchema.HasField("Capital") {
Expand Down
10 changes: 0 additions & 10 deletions schema/schema.go
Expand Up @@ -101,16 +101,6 @@ type Schema struct {
MissingValues []string `json:"missingValues,omitempty"`
}

// Headers returns the headers of the tabular data described
// by the schema.
func (s *Schema) Headers() []string {
var h []string
for i := range s.Fields {
h = append(h, s.Fields[i].Name)
}
return h
}

// GetField fetches the index and field referenced by the name argument.
func (s *Schema) GetField(name string) (*Field, int) {
for i := range s.Fields {
Expand Down
14 changes: 0 additions & 14 deletions schema/schema_test.go
Expand Up @@ -227,20 +227,6 @@ func TestRead_Error(t *testing.T) {
}
}

func TestHeaders(t *testing.T) {
// Empty schema, empty headers.
s := Schema{}
if len(s.Headers()) > 0 {
t.Errorf("want:0 got:%d", len(s.Headers()))
}

s1 := Schema{Fields: []Field{{Name: "f1"}, {Name: "f2"}}}
expected := []string{"f1", "f2"}
if !reflect.DeepEqual(s1.Headers(), expected) {
t.Errorf("want:%v got:%v", expected, s1.Headers())
}
}

func TestSchema_Decode(t *testing.T) {
t.Run("NoImplicitCast", func(t *testing.T) {
t1 := struct {
Expand Down

0 comments on commit 9997dad

Please sign in to comment.