Skip to content

Commit

Permalink
Added ParseSchemaFile function
Browse files Browse the repository at this point in the history
  • Loading branch information
serejja committed Mar 26, 2015
1 parent c90eb85 commit abf55d5
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package avro
import (
"encoding/json"
"fmt"
"io/ioutil"
"math"
"reflect"
)
Expand Down Expand Up @@ -419,10 +420,10 @@ func (this *SchemaField) MarshalJSON() ([]byte, error) {
Default interface{} `json:"default"`
Type Schema `json:"type,omitempty"`
}{
Name: this.Name,
Doc: this.Doc,
Name: this.Name,
Doc: this.Doc,
Default: this.Default,
Type: this.Type,
Type: this.Type,
})
} else {
return json.Marshal(struct {
Expand All @@ -431,10 +432,10 @@ func (this *SchemaField) MarshalJSON() ([]byte, error) {
Default interface{} `json:"default,omitempty"`
Type Schema `json:"type,omitempty"`
}{
Name: this.Name,
Doc: this.Doc,
Name: this.Name,
Doc: this.Doc,
Default: this.Default,
Type: this.Type,
Type: this.Type,
})
}
}
Expand Down Expand Up @@ -699,6 +700,17 @@ func (this *FixedSchema) MarshalJSON() ([]byte, error) {
})
}

// Parses a given file.
// May return an error if schema is not parsable or file does not exist.
func ParseSchemaFile(file string) (Schema, error) {
fileContents, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}

return ParseSchema(string(fileContents))
}

// Parses a given schema without provided schemas to reuse.
// Equivalent to call ParseSchemaWithResistry(rawSchema, make(map[string]Schema))
// May return an error if schema is not parsable or has insufficient information about any type.
Expand Down

0 comments on commit abf55d5

Please sign in to comment.