Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
7db3511e
Commit
7db3511e
authored
Aug 27, 2016
by
Miek Gieben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add RegisterDirective
parent
1f943d4f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
+62
-0
core/dnsserver/directives.go
core/dnsserver/directives.go
+62
-0
No files found.
core/dnsserver/directives.go
View file @
7db3511e
package
dnsserver
package
dnsserver
import
(
"fmt"
"os"
"strings"
)
// RegisterDirective splices name into the list of directives
// immediately before another directive. .
// If before is empty,
// the directive will be appended to the end of the list.
//
// It is imperative that directives execute in the proper
// order, and hard-coding the list of directives guarantees
// a correct, absolute order every time. This function is
// convenient when developing a plugin, but it does not
// guarantee absolute ordering. Multiple plugins registering
// directives with this function will lead to non-
// deterministic builds and buggy software.
//
// Directive names must be lower-cased and unique. Any errors
// here are fatal, and even successful calls print a message
// to stdout as a reminder to use it only in development.
func
RegisterDirective
(
name
,
before
string
)
{
if
name
==
""
{
fmt
.
Println
(
"[FATAL] Cannot register empty directive name"
)
os
.
Exit
(
1
)
}
if
strings
.
ToLower
(
name
)
!=
name
{
fmt
.
Printf
(
"[FATAL] %s: directive name must be lowercase
\n
"
,
name
)
os
.
Exit
(
1
)
}
for
_
,
dir
:=
range
directives
{
if
dir
==
name
{
fmt
.
Printf
(
"[FATAL] %s: directive name already exists
\n
"
,
name
)
os
.
Exit
(
1
)
}
}
if
before
==
""
{
directives
=
append
(
directives
,
name
)
}
else
{
var
found
bool
for
i
,
dir
:=
range
directives
{
if
dir
==
before
{
directives
=
append
(
directives
[
:
i
],
append
([]
string
{
name
},
directives
[
i
:
]
...
)
...
)
found
=
true
break
}
}
if
!
found
{
fmt
.
Printf
(
"[FATAL] %s: directive not found
\n
"
,
before
)
os
.
Exit
(
1
)
}
}
msg
:=
fmt
.
Sprintf
(
"Registered directive '%s' "
,
name
)
if
before
==
""
{
msg
+=
"at end of list"
}
else
{
msg
+=
fmt
.
Sprintf
(
"before '%s'"
,
before
)
}
fmt
.
Printf
(
"[INFO] %s
\n
"
,
msg
)
}
// Add here, and in core/coredns.go to use them.
// Add here, and in core/coredns.go to use them.
// Directives are registered in the order they should be
// Directives are registered in the order they should be
...
...
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