Skip to content

Commit 47d2d8e

Browse files
committed
update
1 parent bb32496 commit 47d2d8e

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ type Context interface {
256256
Accept() *Accepts
257257
Protocol() string
258258
Site() string
259+
SiteRoot() string
260+
LangURI(lang string) string
259261
FullRequestURI() string
260262
RequestURI() string
261263
Scheme() string

context_x_base.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,11 @@ func (c *XContext) URLFor(uri string, relative ...bool) string {
500500
if len(uri) == 0 {
501501
return c.Site()
502502
}
503-
return c.siteRoot() + c.RelativeURL(uri)
503+
return c.SiteRoot() + c.RelativeURL(uri)
504504
}
505505

506506
func (c *XContext) URLByName(name string, args ...interface{}) string {
507-
return c.siteRoot() + c.echo.URIWithContext(c, name, args...)
507+
return c.SiteRoot() + c.echo.URIWithContext(c, name, args...)
508508
}
509509

510510
func (c *XContext) RelativeURLByName(name string, args ...interface{}) string {

context_x_request.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,15 +507,15 @@ func (c *XContext) Protocol() string {
507507

508508
// Site returns base site url as scheme://domain/ type.
509509
func (c *XContext) Site() string {
510-
return c.siteRoot() + `/`
510+
return c.SiteRoot() + `/`
511511
}
512512

513-
func (c *XContext) siteRoot() string {
513+
func (c *XContext) SiteRoot() string {
514514
return c.Scheme() + `://` + c.Request().Host()
515515
}
516516

517517
func (c *XContext) FullRequestURI() string {
518-
return c.siteRoot() + c.RequestURI()
518+
return c.SiteRoot() + c.RequestURI()
519519
}
520520

521521
func (c *XContext) RequestURI() string {
@@ -529,6 +529,21 @@ func (c *XContext) RequestURI() string {
529529
return c.Request().URI()
530530
}
531531

532+
func (c *XContext) DispatchURI() string {
533+
q := c.Request().URL().RawQuery()
534+
if len(q) > 0 {
535+
q = `?` + q
536+
}
537+
return c.DispatchPath() + q
538+
}
539+
540+
func (c *XContext) LangURI(lang string) string {
541+
if len(lang) > 0 {
542+
lang = `/` + lang
543+
}
544+
return lang + c.DispatchURI()
545+
}
546+
532547
// Scheme returns request scheme as `http` or `https`.
533548
func (c *XContext) Scheme() string {
534549
scheme := c.Header(HeaderXForwardedProto)

render_data.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package echo
33
import (
44
"database/sql"
55
"html/template"
6-
"strings"
76
"time"
87

98
"github.com/admpub/humanize"
@@ -163,8 +162,16 @@ func (r *RenderData) Site() string {
163162
return r.ctx.Site()
164163
}
165164

165+
func (r *RenderData) SiteRoot() string {
166+
return r.ctx.SiteRoot()
167+
}
168+
169+
func (r *RenderData) LangURI(lang string) string {
170+
return r.ctx.LangURI(lang)
171+
}
172+
166173
func (r *RenderData) SiteURI() string {
167-
return r.Site() + strings.TrimPrefix(r.URI(), `/`)
174+
return r.SiteRoot() + r.URI()
168175
}
169176

170177
func (r *RenderData) FullURL(myURL string) string {

0 commit comments

Comments
 (0)