aboutsummaryrefslogtreecommitdiff
path: root/app/urls.go
diff options
context:
space:
mode:
Diffstat (limited to 'app/urls.go')
-rw-r--r--app/urls.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/app/urls.go b/app/urls.go
new file mode 100644
index 0000000..8cceb37
--- /dev/null
+++ b/app/urls.go
@@ -0,0 +1,51 @@
1package app
2
3import (
4 glecho "code.crute.us/mcrute/golib/echo"
5 "github.com/labstack/echo/v4"
6)
7
8// AppURL is an interface to building URLs to the application. This exists
9// because the Echo reverse URL functionality requires keeping references to
10// handler functions for the ability to reverse URLs which doesn't work at all
11// for the structure of this application. This interface is effectively named
12// URLs. If Echo supports named URLs in the future this struct can be removed.
13type AppURL struct{}
14
15func (u AppURL) Account(c echo.Context, provider string, shortName *string) string {
16 parts := []string{"/api/account"}
17
18 if provider != "" {
19 parts = append(parts, provider)
20 }
21
22 if shortName != nil {
23 parts = append(parts, *shortName)
24 }
25
26 return glecho.URLFor(c, parts...).String()
27}
28
29func (u AppURL) User(c echo.Context, username *string) string {
30 if username != nil {
31 return glecho.URLFor(c, "/api/user", *username).String()
32 } else {
33 return glecho.URLFor(c, "/api/user").String()
34 }
35}
36
37func (u AppURL) AccountConsole(c echo.Context, provider, shortName string, redir bool) string {
38 au := glecho.URLFor(c, "/api/account", provider, shortName, "console")
39 if redir {
40 au = au.Query("redirect", "1")
41 }
42 return au.String()
43}
44
45func (u AppURL) AccountCredentials(c echo.Context, provider, shortName string, region string) string {
46 if region != "" {
47 return glecho.URLFor(c, "/api/account", provider, shortName, "credentials", region).String()
48 } else {
49 return glecho.URLFor(c, "/api/account", provider, shortName, "credentials").String()
50 }
51}