mirror of
https://github.com/labstack/echo.git
synced 2024-11-30 08:46:41 +02:00
go fmt ./...
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
d41a8a3c74
commit
eef1574969
2
echo.go
2
echo.go
@ -134,7 +134,7 @@ const (
|
|||||||
Location = "Location"
|
Location = "Location"
|
||||||
Upgrade = "Upgrade"
|
Upgrade = "Upgrade"
|
||||||
Vary = "Vary"
|
Vary = "Vary"
|
||||||
WWWAuthenticate = "WWW-Authenticate"
|
WWWAuthenticate = "WWW-Authenticate"
|
||||||
|
|
||||||
//-----------
|
//-----------
|
||||||
// Protocols
|
// Protocols
|
||||||
|
@ -4,12 +4,12 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||||
<title>Echo</title>
|
<title>Echo</title>
|
||||||
<link rel="shortcut icon" href="favicon.ico" />
|
<link rel="shortcut icon" href="favicon.ico"/>
|
||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Echo!</h1>
|
<h1>Echo!</h1>
|
||||||
<script src="/scripts/main.js"></script>
|
<script src="/scripts/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -43,7 +43,7 @@ func BasicAuth(fn BasicValidateFunc) echo.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.Response().Header().Set(echo.WWWAuthenticate, Basic + " realm=Restricted")
|
c.Response().Header().Set(echo.WWWAuthenticate, Basic+" realm=Restricted")
|
||||||
return echo.NewHTTPError(http.StatusUnauthorized)
|
return echo.NewHTTPError(http.StatusUnauthorized)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,20 +36,20 @@ func TestBasicAuth(t *testing.T) {
|
|||||||
req.Header.Set(echo.Authorization, auth)
|
req.Header.Set(echo.Authorization, auth)
|
||||||
he := ba(c).(*echo.HTTPError)
|
he := ba(c).(*echo.HTTPError)
|
||||||
assert.Equal(t, http.StatusUnauthorized, he.Code())
|
assert.Equal(t, http.StatusUnauthorized, he.Code())
|
||||||
assert.Equal(t, Basic + " realm=Restricted", rec.Header().Get(echo.WWWAuthenticate))
|
assert.Equal(t, Basic+" realm=Restricted", rec.Header().Get(echo.WWWAuthenticate))
|
||||||
|
|
||||||
// Empty Authorization header
|
// Empty Authorization header
|
||||||
req.Header.Set(echo.Authorization, "")
|
req.Header.Set(echo.Authorization, "")
|
||||||
he = ba(c).(*echo.HTTPError)
|
he = ba(c).(*echo.HTTPError)
|
||||||
assert.Equal(t, http.StatusUnauthorized, he.Code())
|
assert.Equal(t, http.StatusUnauthorized, he.Code())
|
||||||
assert.Equal(t, Basic + " realm=Restricted", rec.Header().Get(echo.WWWAuthenticate))
|
assert.Equal(t, Basic+" realm=Restricted", rec.Header().Get(echo.WWWAuthenticate))
|
||||||
|
|
||||||
// Invalid Authorization header
|
// Invalid Authorization header
|
||||||
auth = base64.StdEncoding.EncodeToString([]byte("invalid"))
|
auth = base64.StdEncoding.EncodeToString([]byte("invalid"))
|
||||||
req.Header.Set(echo.Authorization, auth)
|
req.Header.Set(echo.Authorization, auth)
|
||||||
he = ba(c).(*echo.HTTPError)
|
he = ba(c).(*echo.HTTPError)
|
||||||
assert.Equal(t, http.StatusUnauthorized, he.Code())
|
assert.Equal(t, http.StatusUnauthorized, he.Code())
|
||||||
assert.Equal(t, Basic + " realm=Restricted", rec.Header().Get(echo.WWWAuthenticate))
|
assert.Equal(t, Basic+" realm=Restricted", rec.Header().Get(echo.WWWAuthenticate))
|
||||||
|
|
||||||
// WebSocket
|
// WebSocket
|
||||||
c.Request().Header.Set(echo.Upgrade, echo.WebSocket)
|
c.Request().Header.Set(echo.Upgrade, echo.WebSocket)
|
||||||
|
@ -5,12 +5,13 @@
|
|||||||
<title>File Upload</title>
|
<title>File Upload</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Upload Files</h1>
|
<h1>Upload Files</h1>
|
||||||
<form action="/upload" method=post enctype="multipart/form-data">
|
|
||||||
Name: <input type="text" name="name"><br>
|
<form action="/upload" method=post enctype="multipart/form-data">
|
||||||
Email: <input type="email" name="email"><br>
|
Name: <input type="text" name="name"><br>
|
||||||
Files: <input type="file" name="files" multiple><br><br>
|
Email: <input type="email" name="email"><br>
|
||||||
<input type="submit" value="Submit">
|
Files: <input type="file" name="files" multiple><br><br>
|
||||||
</form>
|
<input type="submit" value="Submit">
|
||||||
|
</form>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Upload Files</h1>
|
<h1>Upload Files</h1>
|
||||||
|
|
||||||
<form action="/upload" method=post enctype="multipart/form-data">
|
<form action="/upload" method=post enctype="multipart/form-data">
|
||||||
Name: <input type="text" name="name"><br>
|
Name: <input type="text" name="name"><br>
|
||||||
Email: <input type="email" name="email"><br>
|
Email: <input type="email" name="email"><br>
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
<title>WebSocket</title>
|
<title>WebSocket</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p id="output"></p>
|
<p id="output"></p>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var loc = window.location;
|
var loc = window.location;
|
||||||
var uri = 'ws:';
|
var uri = 'ws:';
|
||||||
|
|
||||||
@ -31,6 +31,7 @@
|
|||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
ws.send('Hello, Server!');
|
ws.send('Hello, Server!');
|
||||||
}, 1000);
|
}, 1000);
|
||||||
</script>
|
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
58
router.go
58
router.go
@ -75,7 +75,7 @@ func (r *Router) Add(method, path string, h HandlerFunc, e *Echo) {
|
|||||||
} else if path[i] == '*' {
|
} else if path[i] == '*' {
|
||||||
r.insert(method, path[:i], nil, stype, nil, e)
|
r.insert(method, path[:i], nil, stype, nil, e)
|
||||||
pnames = append(pnames, "_name")
|
pnames = append(pnames, "_name")
|
||||||
r.insert(method, path[:i + 1], h, mtype, pnames, e)
|
r.insert(method, path[:i+1], h, mtype, pnames, e)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,59 +215,59 @@ func (n *node) findChildWithType(t ntype) *node {
|
|||||||
func (r *Router) findTree(method string) (n *node) {
|
func (r *Router) findTree(method string) (n *node) {
|
||||||
switch method[0] {
|
switch method[0] {
|
||||||
case 'G': // GET
|
case 'G': // GET
|
||||||
m := uint32(method[2]) << 8 | uint32(method[1]) << 16 | uint32(method[0]) << 24
|
m := uint32(method[2])<<8 | uint32(method[1])<<16 | uint32(method[0])<<24
|
||||||
if m == 0x47455400 {
|
if m == 0x47455400 {
|
||||||
n = r.getTree
|
n = r.getTree
|
||||||
}
|
}
|
||||||
case 'P': // POST, PUT or PATCH
|
case 'P': // POST, PUT or PATCH
|
||||||
switch method[1] {
|
switch method[1] {
|
||||||
case 'O': // POST
|
case 'O': // POST
|
||||||
m := uint32(method[3]) | uint32(method[2]) << 8 | uint32(method[1]) << 16 |
|
m := uint32(method[3]) | uint32(method[2])<<8 | uint32(method[1])<<16 |
|
||||||
uint32(method[0]) << 24
|
uint32(method[0])<<24
|
||||||
if m == 0x504f5354 {
|
if m == 0x504f5354 {
|
||||||
n = r.postTree
|
n = r.postTree
|
||||||
}
|
}
|
||||||
case 'U': // PUT
|
case 'U': // PUT
|
||||||
m := uint32(method[2]) << 8 | uint32(method[1]) << 16 | uint32(method[0]) << 24
|
m := uint32(method[2])<<8 | uint32(method[1])<<16 | uint32(method[0])<<24
|
||||||
if m == 0x50555400 {
|
if m == 0x50555400 {
|
||||||
n = r.putTree
|
n = r.putTree
|
||||||
}
|
}
|
||||||
case 'A': // PATCH
|
case 'A': // PATCH
|
||||||
m := uint64(method[4]) << 24 | uint64(method[3]) << 32 | uint64(method[2]) << 40 |
|
m := uint64(method[4])<<24 | uint64(method[3])<<32 | uint64(method[2])<<40 |
|
||||||
uint64(method[1]) << 48 | uint64(method[0]) << 56
|
uint64(method[1])<<48 | uint64(method[0])<<56
|
||||||
if m == 0x5041544348000000 {
|
if m == 0x5041544348000000 {
|
||||||
n = r.patchTree
|
n = r.patchTree
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'D': // DELETE
|
case 'D': // DELETE
|
||||||
m := uint64(method[5]) << 16 | uint64(method[4]) << 24 | uint64(method[3]) << 32 |
|
m := uint64(method[5])<<16 | uint64(method[4])<<24 | uint64(method[3])<<32 |
|
||||||
uint64(method[2]) << 40 | uint64(method[1]) << 48 | uint64(method[0]) << 56
|
uint64(method[2])<<40 | uint64(method[1])<<48 | uint64(method[0])<<56
|
||||||
if m == 0x44454c4554450000 {
|
if m == 0x44454c4554450000 {
|
||||||
n = r.deleteTree
|
n = r.deleteTree
|
||||||
}
|
}
|
||||||
case 'C': // CONNECT
|
case 'C': // CONNECT
|
||||||
m := uint64(method[6]) << 8 | uint64(method[5]) << 16 | uint64(method[4]) << 24 |
|
m := uint64(method[6])<<8 | uint64(method[5])<<16 | uint64(method[4])<<24 |
|
||||||
uint64(method[3]) << 32 | uint64(method[2]) << 40 | uint64(method[1]) << 48 |
|
uint64(method[3])<<32 | uint64(method[2])<<40 | uint64(method[1])<<48 |
|
||||||
uint64(method[0]) << 56
|
uint64(method[0])<<56
|
||||||
if m == 0x434f4e4e45435400 {
|
if m == 0x434f4e4e45435400 {
|
||||||
n = r.connectTree
|
n = r.connectTree
|
||||||
}
|
}
|
||||||
case 'H': // HEAD
|
case 'H': // HEAD
|
||||||
m := uint32(method[3]) | uint32(method[2]) << 8 | uint32(method[1]) << 16 |
|
m := uint32(method[3]) | uint32(method[2])<<8 | uint32(method[1])<<16 |
|
||||||
uint32(method[0]) << 24
|
uint32(method[0])<<24
|
||||||
if m == 0x48454144 {
|
if m == 0x48454144 {
|
||||||
n = r.headTree
|
n = r.headTree
|
||||||
}
|
}
|
||||||
case 'O': // OPTIONS
|
case 'O': // OPTIONS
|
||||||
m := uint64(method[6]) << 8 | uint64(method[5]) << 16 | uint64(method[4]) << 24 |
|
m := uint64(method[6])<<8 | uint64(method[5])<<16 | uint64(method[4])<<24 |
|
||||||
uint64(method[3]) << 32 | uint64(method[2]) << 40 | uint64(method[1]) << 48 |
|
uint64(method[3])<<32 | uint64(method[2])<<40 | uint64(method[1])<<48 |
|
||||||
uint64(method[0]) << 56
|
uint64(method[0])<<56
|
||||||
if m == 0x4f5054494f4e5300 {
|
if m == 0x4f5054494f4e5300 {
|
||||||
n = r.optionsTree
|
n = r.optionsTree
|
||||||
}
|
}
|
||||||
case 'T': // TRACE
|
case 'T': // TRACE
|
||||||
m := uint64(method[4]) << 24 | uint64(method[3]) << 32 | uint64(method[2]) << 40 |
|
m := uint64(method[4])<<24 | uint64(method[3])<<32 | uint64(method[2])<<40 |
|
||||||
uint64(method[1]) << 48 | uint64(method[0]) << 56
|
uint64(method[1])<<48 | uint64(method[0])<<56
|
||||||
if m == 0x5452414345000000 {
|
if m == 0x5452414345000000 {
|
||||||
n = r.traceTree
|
n = r.traceTree
|
||||||
}
|
}
|
||||||
@ -286,18 +286,18 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo
|
|||||||
// Strip trailing slash
|
// Strip trailing slash
|
||||||
if r.echo.stripTrailingSlash {
|
if r.echo.stripTrailingSlash {
|
||||||
l := len(path)
|
l := len(path)
|
||||||
if path[l - 1] == '/' {
|
if path[l-1] == '/' {
|
||||||
path = path[:l - 1]
|
path = path[:l-1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
search = path
|
search = path
|
||||||
c *node // Child node
|
c *node // Child node
|
||||||
n int // Param counter
|
n int // Param counter
|
||||||
nt ntype // Next type
|
nt ntype // Next type
|
||||||
nn *node // Next node
|
nn *node // Next node
|
||||||
ns string // Next search
|
ns string // Next search
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: Check empty path???
|
// TODO: Check empty path???
|
||||||
@ -369,7 +369,7 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Param node
|
// Param node
|
||||||
Param:
|
Param:
|
||||||
c = cn.findChildWithType(ptype)
|
c = cn.findChildWithType(ptype)
|
||||||
if c != nil {
|
if c != nil {
|
||||||
// Save next
|
// Save next
|
||||||
@ -389,12 +389,12 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Match-any node
|
// Match-any node
|
||||||
MatchAny:
|
MatchAny:
|
||||||
// c = cn.getChild()
|
// c = cn.getChild()
|
||||||
c = cn.findChildWithType(mtype)
|
c = cn.findChildWithType(mtype)
|
||||||
if c != nil {
|
if c != nil {
|
||||||
cn = c
|
cn = c
|
||||||
ctx.pvalues[len(ctx.pvalues) - 1] = search
|
ctx.pvalues[len(ctx.pvalues)-1] = search
|
||||||
search = "" // End search
|
search = "" // End search
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -4,17 +4,28 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
{% if page_description %}<meta name="description" content="{{ page_description }}">{% endif %}
|
{% if page_description %}
|
||||||
{% if site_author %}<meta name="author" content="{{ site_author }}">{% endif %}
|
<meta name="description" content="{{ page_description }}">
|
||||||
{% if canonical_url %}<link rel="canonical" href="{{ canonical_url }}">{% endif %}
|
{% endif %}
|
||||||
{% if favicon %}<link rel="shortcut icon" href="{{ favicon }}">
|
{% if site_author %}
|
||||||
{% else %}<link rel="shortcut icon" href="{{ base_url }}/img/favicon.ico">{% endif %}
|
<meta name="author" content="{{ site_author }}">
|
||||||
|
{% endif %}
|
||||||
|
{% if canonical_url %}
|
||||||
|
<link rel="canonical" href="{{ canonical_url }}">
|
||||||
|
{% endif %}
|
||||||
|
{% if favicon %}
|
||||||
|
<link rel="shortcut icon" href="{{ favicon }}">
|
||||||
|
{% else %}
|
||||||
|
<link rel="shortcut icon" href="{{ base_url }}/img/favicon.ico">
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<title>{% if page_title %}{{ page_title }} - {% endif %}{{ config.extra.site_title }}</title>
|
<title>{% if page_title %}{{ page_title }} - {% endif %}{{
|
||||||
|
config.extra.site_title }}</title>
|
||||||
|
|
||||||
<link href="{{ base_url }}/css/bootstrap-custom.min.css" rel="stylesheet">
|
<link href="{{ base_url }}/css/bootstrap-custom.min.css" rel="stylesheet">
|
||||||
<link href="{{ base_url }}/css/font-awesome-4.0.3.css" rel="stylesheet">
|
<link href="{{ base_url }}/css/font-awesome-4.0.3.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/tomorrow-night.min.css">
|
<link rel="stylesheet"
|
||||||
|
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/tomorrow-night.min.css">
|
||||||
<link href="{{ base_url }}/css/base.css" rel="stylesheet">
|
<link href="{{ base_url }}/css/base.css" rel="stylesheet">
|
||||||
<link href="{{ base_url }}/css/echo.css" rel="stylesheet">
|
<link href="{{ base_url }}/css/echo.css" rel="stylesheet">
|
||||||
{%- for path in extra_css %}
|
{%- for path in extra_css %}
|
||||||
@ -23,8 +34,10 @@
|
|||||||
|
|
||||||
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
|
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
|
||||||
<!--[if lt IE 9]>
|
<!--[if lt IE 9]>
|
||||||
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
|
<script
|
||||||
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
|
src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
|
||||||
|
<script
|
||||||
|
src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
|
|
||||||
{% if google_analytics %}
|
{% if google_analytics %}
|
||||||
@ -36,7 +49,8 @@
|
|||||||
|
|
||||||
ga('create', '{{ google_analytics[0] }}', '{{ google_analytics[1] }}');
|
ga('create', '{{ google_analytics[0] }}', '{{ google_analytics[1] }}');
|
||||||
ga('send', 'pageview');
|
ga('send', 'pageview');
|
||||||
</script>
|
|
||||||
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"gulp": "^3.8.11",
|
"gulp": "^3.8.11",
|
||||||
"gulp-gh-pages": "^0.5.1",
|
"gulp-gh-pages": "^0.5.1",
|
||||||
"gulp-shell": "^0.4.1"
|
"gulp-shell": "^0.4.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user