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
1bdbf9d6
Commit
1bdbf9d6
authored
Jun 03, 2016
by
Marc Guasch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add parseUpstream method
parent
2536ea74
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
5 deletions
+66
-5
middleware/proxy/upstream.go
middleware/proxy/upstream.go
+66
-5
No files found.
middleware/proxy/upstream.go
View file @
1bdbf9d6
package
proxy
package
proxy
import
(
import
(
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
...
@@ -56,16 +57,37 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
...
@@ -56,16 +57,37 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
if
!
c
.
Args
(
&
upstream
.
from
)
{
if
!
c
.
Args
(
&
upstream
.
from
)
{
return
upstreams
,
c
.
ArgErr
()
return
upstreams
,
c
.
ArgErr
()
}
}
to
:=
c
.
RemainingArgs
()
if
len
(
to
)
==
0
{
var
to
[]
string
return
upstreams
,
c
.
ArgErr
()
for
_
,
t
:=
range
c
.
RemainingArgs
()
{
parsed
,
err
:=
parseUpstream
(
t
)
if
err
!=
nil
{
return
upstreams
,
err
}
to
=
append
(
to
,
parsed
...
)
}
}
for
c
.
NextBlock
()
{
for
c
.
NextBlock
()
{
switch
c
.
Val
()
{
case
"upstream"
:
if
!
c
.
NextArg
()
{
return
upstreams
,
c
.
ArgErr
()
}
parsed
,
err
:=
parseUpstream
(
c
.
Val
())
if
err
!=
nil
{
return
upstreams
,
err
}
to
=
append
(
to
,
parsed
...
)
default
:
if
err
:=
parseBlock
(
&
c
,
upstream
);
err
!=
nil
{
if
err
:=
parseBlock
(
&
c
,
upstream
);
err
!=
nil
{
return
upstreams
,
err
return
upstreams
,
err
}
}
}
}
}
if
len
(
to
)
==
0
{
return
upstreams
,
c
.
ArgErr
()
}
upstream
.
Hosts
=
make
([]
*
UpstreamHost
,
len
(
to
))
upstream
.
Hosts
=
make
([]
*
UpstreamHost
,
len
(
to
))
for
i
,
host
:=
range
to
{
for
i
,
host
:=
range
to
{
...
@@ -134,6 +156,45 @@ func (u *staticUpstream) NewHost(host string) (*UpstreamHost, error) {
...
@@ -134,6 +156,45 @@ func (u *staticUpstream) NewHost(host string) (*UpstreamHost, error) {
return
uh
,
nil
return
uh
,
nil
}
}
func
parseUpstream
(
u
string
)
([]
string
,
error
)
{
if
!
strings
.
HasPrefix
(
u
,
"unix:"
)
{
colonIdx
:=
strings
.
LastIndex
(
u
,
":"
)
protoIdx
:=
strings
.
Index
(
u
,
"://"
)
if
colonIdx
!=
-
1
&&
colonIdx
!=
protoIdx
{
us
:=
u
[
:
colonIdx
]
ports
:=
u
[
len
(
us
)
+
1
:
]
if
separators
:=
strings
.
Count
(
ports
,
"-"
);
separators
>
1
{
return
nil
,
fmt
.
Errorf
(
"port range [%s] is invalid"
,
ports
)
}
else
if
separators
==
1
{
portsStr
:=
strings
.
Split
(
ports
,
"-"
)
pIni
,
err
:=
strconv
.
Atoi
(
portsStr
[
0
])
if
err
!=
nil
{
return
nil
,
err
}
pEnd
,
err
:=
strconv
.
Atoi
(
portsStr
[
1
])
if
err
!=
nil
{
return
nil
,
err
}
if
pEnd
<=
pIni
{
return
nil
,
fmt
.
Errorf
(
"port range [%s] is invalid"
,
ports
)
}
hosts
:=
[]
string
{}
for
p
:=
pIni
;
p
<=
pEnd
;
p
++
{
hosts
=
append
(
hosts
,
fmt
.
Sprintf
(
"%s:%d"
,
us
,
p
))
}
return
hosts
,
nil
}
}
}
return
[]
string
{
u
},
nil
}
func
parseBlock
(
c
*
parse
.
Dispenser
,
u
*
staticUpstream
)
error
{
func
parseBlock
(
c
*
parse
.
Dispenser
,
u
*
staticUpstream
)
error
{
switch
c
.
Val
()
{
switch
c
.
Val
()
{
case
"policy"
:
case
"policy"
:
...
...
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