Refactor URL build from config
This commit is contained in:
parent
d51b79ae96
commit
2062bd92e8
|
@ -33,6 +33,7 @@ package config // import "happydns.org/config"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
@ -49,6 +50,15 @@ type Options struct {
|
||||||
StorageEngine string
|
StorageEngine string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *Options) BuildURL(url string) string {
|
||||||
|
return fmt.Sprintf("%s%s%s", o.ExternalURL, o.BaseURL, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *Options) BuildURL_noescape(url string, args ...interface{}) string {
|
||||||
|
args = append([]interface{}{o.ExternalURL, o.BaseURL}, args...)
|
||||||
|
return fmt.Sprintf("%s%s"+url, args...)
|
||||||
|
}
|
||||||
|
|
||||||
func ConsolidateConfig() (opts *Options, err error) {
|
func ConsolidateConfig() (opts *Options, err error) {
|
||||||
// Define defaults options
|
// Define defaults options
|
||||||
opts = &Options{
|
opts = &Options{
|
||||||
|
|
|
@ -32,16 +32,15 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"git.happydns.org/happydns/model"
|
"git.happydns.org/happydns/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (o *Options) GetAccountRecoveryURL(u *happydns.User) string {
|
func (o *Options) GetAccountRecoveryURL(u *happydns.User) string {
|
||||||
return fmt.Sprintf("%s%s/forgotten-password?u=%x&k=%s", o.ExternalURL, o.BaseURL, u.Id, url.QueryEscape(u.GenAccountRecoveryHash(false)))
|
return o.BuildURL_noescape("/forgotten-password?u=%x&k=%s", u.Id, url.QueryEscape(u.GenAccountRecoveryHash(false)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Options) GetRegistrationURL(u *happydns.User) string {
|
func (o *Options) GetRegistrationURL(u *happydns.User) string {
|
||||||
return fmt.Sprintf("%s%s/email-validation?u=%x&k=%s", o.ExternalURL, o.BaseURL, u.Id, url.QueryEscape(u.GenRegistrationHash(false)))
|
return o.BuildURL_noescape("/email-validation?u=%x&k=%s", u.Id, url.QueryEscape(u.GenRegistrationHash(false)))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user