Commit 634b8b70 authored by Matthew Holt's avatar Matthew Holt

Slight refactoring/renaming

parent 0e43271c
......@@ -6,15 +6,17 @@ package config
// the middleware.Controller interface.
type controller struct {
dispenser
parser *parser
}
// newController returns a new controller.
func newController(p *parser) *controller {
return &controller{
dispenser: dispenser{
cursor: -1,
parser: p,
cursor: -1,
filename: p.filename,
},
parser: p,
}
}
......
......@@ -10,10 +10,10 @@ import (
// their instance. It basically dispenses tokens but can
// do so in a structured manner.
type dispenser struct {
parser *parser
cursor int
nesting int
tokens []token
filename string
cursor int
nesting int
tokens []token
}
// Next loads the next token. Returns true if a token
......@@ -124,7 +124,7 @@ func (d *dispenser) ArgErr() error {
// the error in the dispenser after the middleware preparator
// is finished.
func (d *dispenser) Err(msg string) error {
msg = fmt.Sprintf("%s:%d - Parse error: %s", d.parser.filename, d.tokens[d.cursor].line, msg)
msg = fmt.Sprintf("%s:%d - Parse error: %s", d.filename, d.tokens[d.cursor].line, msg)
return errors.New(msg)
}
......
......@@ -14,7 +14,7 @@ import (
// This init function registers middleware. Register middleware
// in the order they should be executed during a request.
// Middleware execute in an order like this: A-B-C-*-C-B-A
// Middleware execute in this order: A-B-C-*-C-B-A
func init() {
register("gzip", gzip.New)
register("header", headers.New)
......@@ -32,7 +32,7 @@ var (
// are bound.
registry = struct {
directiveMap map[string]middleware.Generator
order []string
ordered []string
}{
directiveMap: make(map[string]middleware.Generator),
}
......@@ -43,7 +43,7 @@ var (
// executed in the order they are registered.
func register(directive string, generator middleware.Generator) {
registry.directiveMap[directive] = generator
registry.order = append(registry.order, directive)
registry.ordered = append(registry.ordered, directive)
}
// middlewareRegistered returns whether or not a directive is registered.
......
......@@ -106,7 +106,7 @@ func (p *parser) parseOne() error {
// This function should be called only after p has filled out
// p.other and that the entire server block has been consumed.
func (p *parser) unwrap() error {
for directive := range registry.directiveMap {
for _, directive := range registry.ordered {
if disp, ok := p.other[directive]; ok {
if generator, ok := registry.directiveMap[directive]; ok {
mid, err := generator(disp)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment