mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-04 03:27:23 -05:00 
			
		
		
		
	Slight refactoring/renaming
This commit is contained in:
		
							parent
							
								
									0e43271cc9
								
							
						
					
					
						commit
						634b8b707f
					
				@ -6,15 +6,17 @@ package config
 | 
				
			|||||||
// the middleware.Controller interface.
 | 
					// the middleware.Controller interface.
 | 
				
			||||||
type controller struct {
 | 
					type controller struct {
 | 
				
			||||||
	dispenser
 | 
						dispenser
 | 
				
			||||||
 | 
						parser *parser
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// newController returns a new controller.
 | 
					// newController returns a new controller.
 | 
				
			||||||
func newController(p *parser) *controller {
 | 
					func newController(p *parser) *controller {
 | 
				
			||||||
	return &controller{
 | 
						return &controller{
 | 
				
			||||||
		dispenser: dispenser{
 | 
							dispenser: dispenser{
 | 
				
			||||||
			cursor: -1,
 | 
								cursor:   -1,
 | 
				
			||||||
			parser: p,
 | 
								filename: p.filename,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							parser: p,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -10,10 +10,10 @@ import (
 | 
				
			|||||||
// their instance. It basically dispenses tokens but can
 | 
					// their instance. It basically dispenses tokens but can
 | 
				
			||||||
// do so in a structured manner.
 | 
					// do so in a structured manner.
 | 
				
			||||||
type dispenser struct {
 | 
					type dispenser struct {
 | 
				
			||||||
	parser  *parser
 | 
						filename string
 | 
				
			||||||
	cursor  int
 | 
						cursor   int
 | 
				
			||||||
	nesting int
 | 
						nesting  int
 | 
				
			||||||
	tokens  []token
 | 
						tokens   []token
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Next loads the next token. Returns true if a 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
 | 
					// the error in the dispenser after the middleware preparator
 | 
				
			||||||
// is finished.
 | 
					// is finished.
 | 
				
			||||||
func (d *dispenser) Err(msg string) error {
 | 
					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)
 | 
						return errors.New(msg)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -14,7 +14,7 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// This init function registers middleware. Register middleware
 | 
					// This init function registers middleware. Register middleware
 | 
				
			||||||
// in the order they should be executed during a request.
 | 
					// 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() {
 | 
					func init() {
 | 
				
			||||||
	register("gzip", gzip.New)
 | 
						register("gzip", gzip.New)
 | 
				
			||||||
	register("header", headers.New)
 | 
						register("header", headers.New)
 | 
				
			||||||
@ -32,7 +32,7 @@ var (
 | 
				
			|||||||
	// are bound.
 | 
						// are bound.
 | 
				
			||||||
	registry = struct {
 | 
						registry = struct {
 | 
				
			||||||
		directiveMap map[string]middleware.Generator
 | 
							directiveMap map[string]middleware.Generator
 | 
				
			||||||
		order        []string
 | 
							ordered      []string
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		directiveMap: make(map[string]middleware.Generator),
 | 
							directiveMap: make(map[string]middleware.Generator),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -43,7 +43,7 @@ var (
 | 
				
			|||||||
// executed in the order they are registered.
 | 
					// executed in the order they are registered.
 | 
				
			||||||
func register(directive string, generator middleware.Generator) {
 | 
					func register(directive string, generator middleware.Generator) {
 | 
				
			||||||
	registry.directiveMap[directive] = 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.
 | 
					// 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
 | 
					// This function should be called only after p has filled out
 | 
				
			||||||
// p.other and that the entire server block has been consumed.
 | 
					// p.other and that the entire server block has been consumed.
 | 
				
			||||||
func (p *parser) unwrap() error {
 | 
					func (p *parser) unwrap() error {
 | 
				
			||||||
	for directive := range registry.directiveMap {
 | 
						for _, directive := range registry.ordered {
 | 
				
			||||||
		if disp, ok := p.other[directive]; ok {
 | 
							if disp, ok := p.other[directive]; ok {
 | 
				
			||||||
			if generator, ok := registry.directiveMap[directive]; ok {
 | 
								if generator, ok := registry.directiveMap[directive]; ok {
 | 
				
			||||||
				mid, err := generator(disp)
 | 
									mid, err := generator(disp)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user