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
e2f6c51f
Commit
e2f6c51f
authored
Oct 17, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: Controller has field to persist server state
Also added ServerBlockHostIndex
parent
c4a73784
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
5 deletions
+32
-5
config/config.go
config/config.go
+18
-3
config/setup/controller.go
config/setup/controller.go
+14
-2
No files found.
config/config.go
View file @
e2f6c51f
...
...
@@ -46,8 +46,9 @@ func Load(filename string, input io.Reader) (Group, error) {
// executing the directives that were parsed.
for
i
,
sb
:=
range
serverBlocks
{
onces
:=
makeOnces
()
storages
:=
makeStorages
()
for
_
,
addr
:=
range
sb
.
Addresses
{
for
j
,
addr
:=
range
sb
.
Addresses
{
config
:=
server
.
Config
{
Host
:
addr
.
Host
,
Port
:
addr
.
Port
,
...
...
@@ -75,8 +76,10 @@ func Load(filename string, input io.Reader) (Group, error) {
})
return
err
},
ServerBlockIndex
:
i
,
ServerBlockHosts
:
sb
.
HostList
(),
ServerBlockIndex
:
i
,
ServerBlockHostIndex
:
j
,
ServerBlockHosts
:
sb
.
HostList
(),
ServerBlockStorage
:
storages
[
dir
.
name
],
}
midware
,
err
:=
dir
.
setup
(
controller
)
...
...
@@ -121,6 +124,18 @@ func makeOnces() map[string]*sync.Once {
return
onces
}
// makeStorages makes a map of directive name to interface{}
// so that directives' setup functions can persist state
// between different hosts on the same server block during the
// setup phase.
func
makeStorages
()
map
[
string
]
interface
{}
{
storages
:=
make
(
map
[
string
]
interface
{})
for
_
,
dir
:=
range
directiveOrder
{
storages
[
dir
.
name
]
=
nil
}
return
storages
}
// arrangeBindings groups configurations by their bind address. For example,
// a server that should listen on localhost and another on 127.0.0.1 will
// be grouped into the same address: 127.0.0.1. It will return an error
...
...
config/setup/controller.go
View file @
e2f6c51f
...
...
@@ -29,17 +29,29 @@ type Controller struct {
// server block as it appeared in the input.
ServerBlockIndex
int
// ServerBlockHostIndex is the 0-based index of this
// host as it appeared in the input at the head of the
// server block.
ServerBlockHostIndex
int
// ServerBlockHosts is a list of hosts that are
// associated with this server block. All these
// hosts, consequently, share the same tokens.
ServerBlockHosts
[]
string
// ServerBlockStorage is used by a directive's
// setup function to persist state between all
// the hosts on a server block.
ServerBlockStorage
interface
{}
}
// NewTestController creates a new *Controller for
// the input specified, with a filename of "Testfile"
// the input specified, with a filename of "Testfile".
// The Config is bare, consisting only of a Root of cwd.
//
// Used primarily for testing but needs to be exported so
// add-ons can use this as a convenience.
// add-ons can use this as a convenience. Does not initialize
// the server-block-related fields.
func
NewTestController
(
input
string
)
*
Controller
{
return
&
Controller
{
Config
:
&
server
.
Config
{
...
...
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