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
nexedi
caddy
Commits
b089d14b
Commit
b089d14b
authored
Feb 05, 2016
by
Matt Holt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #548 from captncraig/register
Making directives externally registerable
parents
5b7e0361
e72fc20c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
0 deletions
+48
-0
caddy/directives.go
caddy/directives.go
+17
-0
caddy/directives_test.go
caddy/directives_test.go
+31
-0
No files found.
caddy/directives.go
View file @
b089d14b
...
@@ -68,6 +68,23 @@ var directiveOrder = []directive{
...
@@ -68,6 +68,23 @@ var directiveOrder = []directive{
{
"browse"
,
setup
.
Browse
},
{
"browse"
,
setup
.
Browse
},
}
}
// RegisterDirective adds the given directive to caddy's list of directives.
// Pass the name of a directive you want it to be placed after,
// otherwise it will be placed at the bottom of the stack.
func
RegisterDirective
(
name
string
,
setup
SetupFunc
,
after
string
)
{
dir
:=
directive
{
name
:
name
,
setup
:
setup
}
idx
:=
len
(
directiveOrder
)
for
i
:=
range
directiveOrder
{
if
directiveOrder
[
i
]
.
name
==
after
{
idx
=
i
+
1
break
}
}
newDirectives
:=
append
(
directiveOrder
[
:
idx
],
append
([]
directive
{
dir
},
directiveOrder
[
idx
:
]
...
)
...
)
directiveOrder
=
newDirectives
parse
.
ValidDirectives
[
name
]
=
struct
{}{}
}
// directive ties together a directive name with its setup function.
// directive ties together a directive name with its setup function.
type
directive
struct
{
type
directive
struct
{
name
string
name
string
...
...
caddy/directives_test.go
0 → 100644
View file @
b089d14b
package
caddy
import
(
"reflect"
"testing"
)
func
TestRegister
(
t
*
testing
.
T
)
{
directives
:=
[]
directive
{
{
"dummy"
,
nil
},
{
"dummy2"
,
nil
},
}
directiveOrder
=
directives
RegisterDirective
(
"foo"
,
nil
,
"dummy"
)
if
len
(
directiveOrder
)
!=
3
{
t
.
Fatal
(
"Should have 3 directives now"
)
}
getNames
:=
func
()
(
s
[]
string
)
{
for
_
,
d
:=
range
directiveOrder
{
s
=
append
(
s
,
d
.
name
)
}
return
s
}
if
!
reflect
.
DeepEqual
(
getNames
(),
[]
string
{
"dummy"
,
"foo"
,
"dummy2"
})
{
t
.
Fatalf
(
"directive order doesn't match: %s"
,
getNames
())
}
RegisterDirective
(
"bar"
,
nil
,
"ASDASD"
)
if
!
reflect
.
DeepEqual
(
getNames
(),
[]
string
{
"dummy"
,
"foo"
,
"dummy2"
,
"bar"
})
{
t
.
Fatalf
(
"directive order doesn't match: %s"
,
getNames
())
}
}
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