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
9aaf8132
Commit
9aaf8132
authored
Mar 20, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
There's a std lib function for that
parent
35225fe2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
49 deletions
+7
-49
config/parser.go
config/parser.go
+0
-13
config/parsing.go
config/parsing.go
+7
-4
config/parsing_test.go
config/parsing_test.go
+0
-32
No files found.
config/parser.go
View file @
9aaf8132
...
@@ -4,7 +4,6 @@ import (
...
@@ -4,7 +4,6 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"os"
"os"
"strings"
"github.com/mholt/caddy/middleware"
"github.com/mholt/caddy/middleware"
)
)
...
@@ -183,15 +182,3 @@ func (p *parser) err(kind, msg string) error {
...
@@ -183,15 +182,3 @@ func (p *parser) err(kind, msg string) error {
msg
=
fmt
.
Sprintf
(
"%s:%d - %s error: %s"
,
p
.
filename
,
p
.
line
(),
kind
,
msg
)
msg
=
fmt
.
Sprintf
(
"%s:%d - %s error: %s"
,
p
.
filename
,
p
.
line
(),
kind
,
msg
)
return
errors
.
New
(
msg
)
return
errors
.
New
(
msg
)
}
}
// parseAddress takes a host:port string (val), and returns the host
// and port as separate values. Empty strings can be returned if
// either is missing.
func
parseAddress
(
val
string
)
(
string
,
string
)
{
parts
:=
strings
.
SplitN
(
val
,
":"
,
3
)
if
len
(
parts
)
==
1
{
return
parts
[
0
],
""
}
else
{
return
parts
[
0
],
parts
[
1
]
}
}
config/parsing.go
View file @
9aaf8132
package
config
package
config
import
"errors"
import
(
"errors"
"net"
)
// This file contains the recursive-descent parsing
// This file contains the recursive-descent parsing
// functions.
// functions.
...
@@ -24,12 +27,12 @@ func (p *parser) begin() error {
...
@@ -24,12 +27,12 @@ func (p *parser) begin() error {
// address expects that the current token is a host:port
// address expects that the current token is a host:port
// combination.
// combination.
func
(
p
*
parser
)
address
()
error
{
func
(
p
*
parser
)
address
()
(
err
error
)
{
if
p
.
tkn
()
==
"}"
||
p
.
tkn
()
==
"{"
{
if
p
.
tkn
()
==
"}"
||
p
.
tkn
()
==
"{"
{
return
p
.
err
(
"Syntax"
,
"'"
+
p
.
tkn
()
+
"' is not EOF or address"
)
return
p
.
err
(
"Syntax"
,
"'"
+
p
.
tkn
()
+
"' is not EOF or address"
)
}
}
p
.
cfg
.
Host
,
p
.
cfg
.
Port
=
parseAddress
(
p
.
tkn
())
p
.
cfg
.
Host
,
p
.
cfg
.
Port
,
err
=
net
.
SplitHostPort
(
p
.
tkn
())
return
nil
return
}
}
// addressBlock leads into parsing directives, including
// addressBlock leads into parsing directives, including
...
...
config/parsing_test.go
View file @
9aaf8132
package
config
package
config
import
"testing"
func
TestParseAddress
(
t
*
testing
.
T
)
{
type
addr
struct
{
host
string
port
string
}
testCases
:=
[]
struct
{
input
string
expected
addr
}{
{
input
:
"host:port"
,
expected
:
addr
{
host
:
"host"
,
port
:
"port"
}},
{
input
:
"localhost:1234"
,
expected
:
addr
{
host
:
"localhost"
,
port
:
"1234"
}},
{
input
:
"127.0.0.1:0"
,
expected
:
addr
{
host
:
"127.0.0.1"
,
port
:
"0"
}},
{
input
:
"127.0.0.1"
,
expected
:
addr
{
host
:
"127.0.0.1"
,
port
:
""
}},
{
input
:
"somedomain.com"
,
expected
:
addr
{
host
:
"somedomain.com"
,
port
:
""
}},
{
input
:
"somedomain.com:"
,
expected
:
addr
{
host
:
"somedomain.com"
,
port
:
""
}},
{
input
:
":80"
,
expected
:
addr
{
host
:
""
,
port
:
"80"
}},
{
input
:
"localhost:8080"
,
expected
:
addr
{
host
:
"localhost"
,
port
:
"8080"
}},
{
input
:
""
,
expected
:
addr
{
host
:
""
,
port
:
""
}},
}
for
_
,
test
:=
range
testCases
{
actualHost
,
actualPort
:=
parseAddress
(
test
.
input
)
if
actualHost
!=
test
.
expected
.
host
{
t
.
Errorf
(
"For '%s' expected host '%s' but got '%s'"
,
test
.
input
,
test
.
expected
.
host
,
actualHost
)
}
if
actualPort
!=
test
.
expected
.
port
{
t
.
Errorf
(
"For '%s' expected port '%s' but got '%s'"
,
test
.
input
,
test
.
expected
.
port
,
actualPort
)
}
}
}
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