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() } }