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