api: standardise strip fn names
This commit is contained in:
parent
a8ecbd9717
commit
c57bc6a39b
@ -102,7 +102,7 @@ func commentListHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
domain := stripDomain(*x.Domain)
|
domain := domainStrip(*x.Domain)
|
||||||
path := *x.Path
|
path := *x.Path
|
||||||
|
|
||||||
d, err := domainGet(domain)
|
d, err := domainGet(domain)
|
||||||
|
@ -49,7 +49,7 @@ func commentNewHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
domain := stripDomain(*x.Domain)
|
domain := domainStrip(*x.Domain)
|
||||||
path := *x.Path
|
path := *x.Path
|
||||||
|
|
||||||
d, err := domainGet(domain)
|
d, err := domainGet(domain)
|
||||||
|
@ -81,7 +81,7 @@ func domainDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
domain := stripDomain(*x.Domain)
|
domain := domainStrip(*x.Domain)
|
||||||
isOwner, err := domainOwnershipVerify(o.OwnerHex, domain)
|
isOwner, err := domainOwnershipVerify(o.OwnerHex, domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
||||||
|
@ -150,7 +150,7 @@ func domainImportDisqus(domain string, url string) (int, error) {
|
|||||||
commentHex, err := commentNew(
|
commentHex, err := commentNew(
|
||||||
commenterHex[post.Author.Email],
|
commenterHex[post.Author.Email],
|
||||||
domain,
|
domain,
|
||||||
stripPath(threads[post.ThreadId.Id].URL),
|
pathStrip(threads[post.ThreadId.Id].URL),
|
||||||
parentHex,
|
parentHex,
|
||||||
html2md.Convert(post.Message),
|
html2md.Convert(post.Message),
|
||||||
"approved",
|
"approved",
|
||||||
@ -185,7 +185,7 @@ func domainImportDisqusHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
domain := stripDomain(*x.Domain)
|
domain := domainStrip(*x.Domain)
|
||||||
isOwner, err := domainOwnershipVerify(o.OwnerHex, domain)
|
isOwner, err := domainOwnershipVerify(o.OwnerHex, domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
||||||
|
@ -41,7 +41,7 @@ func domainModeratorDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
domain := stripDomain(*x.Domain)
|
domain := domainStrip(*x.Domain)
|
||||||
authorised, err := domainOwnershipVerify(o.OwnerHex, domain)
|
authorised, err := domainOwnershipVerify(o.OwnerHex, domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
||||||
|
@ -43,7 +43,7 @@ func domainModeratorNewHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
domain := stripDomain(*x.Domain)
|
domain := domainStrip(*x.Domain)
|
||||||
isOwner, err := domainOwnershipVerify(o.OwnerHex, domain)
|
isOwner, err := domainOwnershipVerify(o.OwnerHex, domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
||||||
|
@ -43,7 +43,7 @@ func domainNewHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
domain := stripDomain(*x.Domain)
|
domain := domainStrip(*x.Domain)
|
||||||
|
|
||||||
if err = domainNew(o.OwnerHex, *x.Name, domain); err != nil {
|
if err = domainNew(o.OwnerHex, *x.Name, domain); err != nil {
|
||||||
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
||||||
|
@ -55,7 +55,7 @@ func domainStatisticsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
domain := stripDomain(*x.Domain)
|
domain := domainStrip(*x.Domain)
|
||||||
isOwner, err := domainOwnershipVerify(o.OwnerHex, domain)
|
isOwner, err := domainOwnershipVerify(o.OwnerHex, domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
||||||
|
@ -38,7 +38,7 @@ func domainUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
domain := stripDomain((*x.D).Domain)
|
domain := domainStrip((*x.D).Domain)
|
||||||
isOwner, err := domainOwnershipVerify(o.OwnerHex, domain)
|
isOwner, err := domainOwnershipVerify(o.OwnerHex, domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
||||||
|
@ -8,7 +8,7 @@ var prePlusMatch = regexp.MustCompile(`([^@\+]*)\+?(.*)@.*`)
|
|||||||
var periodsMatch = regexp.MustCompile(`[\.]`)
|
var periodsMatch = regexp.MustCompile(`[\.]`)
|
||||||
var postAtMatch = regexp.MustCompile(`[^@]*(@.*)`)
|
var postAtMatch = regexp.MustCompile(`[^@]*(@.*)`)
|
||||||
|
|
||||||
func stripEmail(email string) string {
|
func emailStrip(email string) string {
|
||||||
postAt := postAtMatch.ReplaceAllString(email, `$1`)
|
postAt := postAtMatch.ReplaceAllString(email, `$1`)
|
||||||
prePlus := prePlusMatch.ReplaceAllString(email, `$1`)
|
prePlus := prePlusMatch.ReplaceAllString(email, `$1`)
|
||||||
strippedEmail := periodsMatch.ReplaceAllString(prePlus, ``) + postAt
|
strippedEmail := periodsMatch.ReplaceAllString(prePlus, ``) + postAt
|
||||||
@ -19,7 +19,7 @@ func stripEmail(email string) string {
|
|||||||
var https = regexp.MustCompile(`(https?://)`)
|
var https = regexp.MustCompile(`(https?://)`)
|
||||||
var trailingSlash = regexp.MustCompile(`(/*$)`)
|
var trailingSlash = regexp.MustCompile(`(/*$)`)
|
||||||
|
|
||||||
func stripDomain(domain string) string {
|
func domainStrip(domain string) string {
|
||||||
noSlash := trailingSlash.ReplaceAllString(domain, ``)
|
noSlash := trailingSlash.ReplaceAllString(domain, ``)
|
||||||
noProtocol := https.ReplaceAllString(noSlash, ``)
|
noProtocol := https.ReplaceAllString(noSlash, ``)
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ func stripDomain(domain string) string {
|
|||||||
|
|
||||||
var pathMatch = regexp.MustCompile(`(https?://[^/]*)`)
|
var pathMatch = regexp.MustCompile(`(https?://[^/]*)`)
|
||||||
|
|
||||||
func stripPath(url string) string {
|
func pathStrip(url string) string {
|
||||||
strippedPath := pathMatch.ReplaceAllString(url, ``)
|
strippedPath := pathMatch.ReplaceAllString(url, ``)
|
||||||
|
|
||||||
return strippedPath
|
return strippedPath
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStripEmailBasics(t *testing.T) {
|
func TestEmailStripBasics(t *testing.T) {
|
||||||
tests := map[string]string{
|
tests := map[string]string{
|
||||||
"test@example.com": "test@example.com",
|
"test@example.com": "test@example.com",
|
||||||
"test+strip@example.com": "test@example.com",
|
"test+strip@example.com": "test@example.com",
|
||||||
@ -12,8 +12,8 @@ func TestStripEmailBasics(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for in, out := range tests {
|
for in, out := range tests {
|
||||||
if stripEmail(in) != out {
|
if emailStrip(in) != out {
|
||||||
t.Errorf("for in=%s expected out=%s got out=%s", in, out, stripEmail(in))
|
t.Errorf("for in=%s expected out=%s got out=%s", in, out, emailStrip(in))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user