Skip to content

Commit

Permalink
improve parser and server reload performance by indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
iwittkau authored and caalberts committed Oct 21, 2018
1 parent 8ab1b5f commit dd3ebb4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func (rtr *router) updateSchema(schemas []types.Schema) {
rtr.Lock()
defer rtr.Unlock()
router := httprouter.New()
for _, schema := range schemas {
router.Handle(schema.Method, schema.Path, handlerFunc(schema))
for i := 0; i < len(schemas); i++ {
router.Handle(schemas[i].Method, schemas[i].Path, handlerFunc(schemas[i]))
}
rtr.Handler = router
}
Expand Down
12 changes: 6 additions & 6 deletions json/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ func (p *Parser) Watch(input chan io.Reader) {
func createSchema(stubs []stub) ([]types.Schema, error) {
schemas := make([]types.Schema, len(stubs))

for i, stub := range stubs {
if f := missingFields(stub); len(f) > 0 {
for i := 0; i < len(stubs); i++ {
if f := missingFields(stubs[i]); len(f) > 0 {
err := fmt.Errorf("missing required fields: %s", strings.Join(f, ", "))
return []types.Schema{}, err
}
schemas[i] = types.Schema{
Method: *stub.Method,
Path: *stub.Path,
Status: *stub.Status,
Response: formatResponse(stub.Response),
Method: *stubs[i].Method,
Path: *stubs[i].Path,
Status: *stubs[i].Status,
Response: formatResponse(stubs[i].Response),
}
}

Expand Down

0 comments on commit dd3ebb4

Please sign in to comment.