Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Łukasz Nowak
caddy
Commits
634b8b70
Commit
634b8b70
authored
Feb 07, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Slight refactoring/renaming
parent
0e43271c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
11 deletions
+13
-11
config/controller.go
config/controller.go
+4
-2
config/dispenser.go
config/dispenser.go
+5
-5
config/middleware.go
config/middleware.go
+3
-3
config/parser.go
config/parser.go
+1
-1
No files found.
config/controller.go
View file @
634b8b70
...
@@ -6,6 +6,7 @@ package config
...
@@ -6,6 +6,7 @@ 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.
...
@@ -13,8 +14,9 @@ func newController(p *parser) *controller {
...
@@ -13,8 +14,9 @@ func newController(p *parser) *controller {
return
&
controller
{
return
&
controller
{
dispenser
:
dispenser
{
dispenser
:
dispenser
{
cursor
:
-
1
,
cursor
:
-
1
,
parser
:
p
,
filename
:
p
.
filename
,
},
},
parser
:
p
,
}
}
}
}
...
...
config/dispenser.go
View file @
634b8b70
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ 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
...
@@ -124,7 +124,7 @@ func (d *dispenser) ArgErr() error {
...
@@ -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
)
}
}
...
...
config/middleware.go
View file @
634b8b70
...
@@ -14,7 +14,7 @@ import (
...
@@ -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 (
...
@@ -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
order
ed
[]
string
}{
}{
directiveMap
:
make
(
map
[
string
]
middleware
.
Generator
),
directiveMap
:
make
(
map
[
string
]
middleware
.
Generator
),
}
}
...
@@ -43,7 +43,7 @@ var (
...
@@ -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
.
order
ed
=
append
(
registry
.
ordered
,
directive
)
}
}
// middlewareRegistered returns whether or not a directive is registered.
// middlewareRegistered returns whether or not a directive is registered.
...
...
config/parser.go
View file @
634b8b70
...
@@ -106,7 +106,7 @@ func (p *parser) parseOne() error {
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment