Skip to content

Commit

Permalink
go fmt ./...
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <vr@labstack.com>
  • Loading branch information
vishr committed Sep 15, 2015
1 parent d41a8a3 commit eef1574
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 62 deletions.
2 changes: 1 addition & 1 deletion echo.go
Expand Up @@ -134,7 +134,7 @@ const (
Location = "Location"
Upgrade = "Upgrade"
Vary = "Vary"
WWWAuthenticate = "WWW-Authenticate"
WWWAuthenticate = "WWW-Authenticate"

//-----------
// Protocols
Expand Down
6 changes: 3 additions & 3 deletions examples/website/public/index.html
Expand Up @@ -4,12 +4,12 @@
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Echo</title>
<link rel="shortcut icon" href="favicon.ico" />
<link rel="shortcut icon" href="favicon.ico"/>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>Echo!</h1>
<script src="/scripts/main.js"></script>
<h1>Echo!</h1>
<script src="/scripts/main.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion middleware/auth.go
Expand Up @@ -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)
}
}
6 changes: 3 additions & 3 deletions middleware/auth_test.go
Expand Up @@ -36,20 +36,20 @@ func TestBasicAuth(t *testing.T) {
req.Header.Set(echo.Authorization, auth)
he := ba(c).(*echo.HTTPError)
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
req.Header.Set(echo.Authorization, "")
he = ba(c).(*echo.HTTPError)
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
auth = base64.StdEncoding.EncodeToString([]byte("invalid"))
req.Header.Set(echo.Authorization, auth)
he = ba(c).(*echo.HTTPError)
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
c.Request().Header.Set(echo.Upgrade, echo.WebSocket)
Expand Down
15 changes: 8 additions & 7 deletions recipes/file-upload/public/index.html
Expand Up @@ -5,12 +5,13 @@
<title>File Upload</title>
</head>
<body>
<h1>Upload Files</h1>
<form action="/upload" method=post enctype="multipart/form-data">
Name: <input type="text" name="name"><br>
Email: <input type="email" name="email"><br>
Files: <input type="file" name="files" multiple><br><br>
<input type="submit" value="Submit">
</form>
<h1>Upload Files</h1>

<form action="/upload" method=post enctype="multipart/form-data">
Name: <input type="text" name="name"><br>
Email: <input type="email" name="email"><br>
Files: <input type="file" name="files" multiple><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
1 change: 1 addition & 0 deletions recipes/streaming-file-upload/public/index.html
Expand Up @@ -6,6 +6,7 @@
</head>
<body>
<h1>Upload Files</h1>

<form action="/upload" method=post enctype="multipart/form-data">
Name: <input type="text" name="name"><br>
Email: <input type="email" name="email"><br>
Expand Down
7 changes: 4 additions & 3 deletions recipes/websocket/public/index.html
Expand Up @@ -5,9 +5,9 @@
<title>WebSocket</title>
</head>
<body>
<p id="output"></p>
<p id="output"></p>

<script>
<script>
var loc = window.location;
var uri = 'ws:';

Expand All @@ -31,6 +31,7 @@
setInterval(function() {
ws.send('Hello, Server!');
}, 1000);
</script>

</script>
</body>
</html>
58 changes: 29 additions & 29 deletions router.go
Expand Up @@ -75,7 +75,7 @@ func (r *Router) Add(method, path string, h HandlerFunc, e *Echo) {
} else if path[i] == '*' {
r.insert(method, path[:i], nil, stype, nil, e)
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
}
}
Expand Down Expand Up @@ -215,59 +215,59 @@ func (n *node) findChildWithType(t ntype) *node {
func (r *Router) findTree(method string) (n *node) {
switch method[0] {
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 {
n = r.getTree
}
case 'P': // POST, PUT or PATCH
switch method[1] {
case 'O': // POST
m := uint32(method[3]) | uint32(method[2]) << 8 | uint32(method[1]) << 16 |
uint32(method[0]) << 24
m := uint32(method[3]) | uint32(method[2])<<8 | uint32(method[1])<<16 |
uint32(method[0])<<24
if m == 0x504f5354 {
n = r.postTree
}
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 {
n = r.putTree
}
case 'A': // PATCH
m := uint64(method[4]) << 24 | uint64(method[3]) << 32 | uint64(method[2]) << 40 |
uint64(method[1]) << 48 | uint64(method[0]) << 56
m := uint64(method[4])<<24 | uint64(method[3])<<32 | uint64(method[2])<<40 |
uint64(method[1])<<48 | uint64(method[0])<<56
if m == 0x5041544348000000 {
n = r.patchTree
}
}
case 'D': // DELETE
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
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
if m == 0x44454c4554450000 {
n = r.deleteTree
}
case 'C': // CONNECT
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[0]) << 56
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[0])<<56
if m == 0x434f4e4e45435400 {
n = r.connectTree
}
case 'H': // HEAD
m := uint32(method[3]) | uint32(method[2]) << 8 | uint32(method[1]) << 16 |
uint32(method[0]) << 24
m := uint32(method[3]) | uint32(method[2])<<8 | uint32(method[1])<<16 |
uint32(method[0])<<24
if m == 0x48454144 {
n = r.headTree
}
case 'O': // OPTIONS
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[0]) << 56
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[0])<<56
if m == 0x4f5054494f4e5300 {
n = r.optionsTree
}
case 'T': // TRACE
m := uint64(method[4]) << 24 | uint64(method[3]) << 32 | uint64(method[2]) << 40 |
uint64(method[1]) << 48 | uint64(method[0]) << 56
m := uint64(method[4])<<24 | uint64(method[3])<<32 | uint64(method[2])<<40 |
uint64(method[1])<<48 | uint64(method[0])<<56
if m == 0x5452414345000000 {
n = r.traceTree
}
Expand All @@ -286,18 +286,18 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo
// Strip trailing slash
if r.echo.stripTrailingSlash {
l := len(path)
if path[l - 1] == '/' {
path = path[:l - 1]
if path[l-1] == '/' {
path = path[:l-1]
}
}

var (
search = path
c *node // Child node
n int // Param counter
nt ntype // Next type
nn *node // Next node
ns string // Next search
c *node // Child node
n int // Param counter
nt ntype // Next type
nn *node // Next node
ns string // Next search
)

// TODO: Check empty path???
Expand Down Expand Up @@ -369,7 +369,7 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo
}

// Param node
Param:
Param:
c = cn.findChildWithType(ptype)
if c != nil {
// Save next
Expand All @@ -389,12 +389,12 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo
}

// Match-any node
MatchAny:
MatchAny:
// c = cn.getChild()
c = cn.findChildWithType(mtype)
if c != nil {
cn = c
ctx.pvalues[len(ctx.pvalues) - 1] = search
ctx.pvalues[len(ctx.pvalues)-1] = search
search = "" // End search
continue
}
Expand Down
34 changes: 24 additions & 10 deletions website/echo/base.html
Expand Up @@ -4,17 +4,28 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% if page_description %}<meta name="description" content="{{ page_description }}">{% endif %}
{% if site_author %}<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 %}
{% if page_description %}
<meta name="description" content="{{ page_description }}">
{% endif %}
{% if site_author %}
<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/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/echo.css" rel="stylesheet">
{%- for path in extra_css %}
Expand All @@ -23,8 +34,10 @@

<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<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>
<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]-->

{% if google_analytics %}
Expand All @@ -36,7 +49,8 @@

ga('create', '{{ google_analytics[0] }}', '{{ google_analytics[1] }}');
ga('send', 'pageview');
</script>

</script>
{% endif %}
</head>

Expand Down
10 changes: 5 additions & 5 deletions website/package.json
@@ -1,7 +1,7 @@
{
"devDependencies": {
"gulp": "^3.8.11",
"gulp-gh-pages": "^0.5.1",
"gulp-shell": "^0.4.1"
}
"devDependencies": {
"gulp": "^3.8.11",
"gulp-gh-pages": "^0.5.1",
"gulp-shell": "^0.4.1"
}
}

0 comments on commit eef1574

Please sign in to comment.