1
mirror of https://gitlab.com/commento/commento.git synced 2025-06-29 22:56:37 -04:00

api: Add go files

I know this is a huge commit, but I can't be bothered to check
this in part by part.
This commit is contained in:
Adhityaa
2018-05-27 20:10:42 +05:30
parent 60e7e59841
commit a090770b73
95 changed files with 4203 additions and 0 deletions

35
api/utils_sanitise.go Normal file
View File

@ -0,0 +1,35 @@
package main
import (
"regexp"
)
var prePlusMatch = regexp.MustCompile(`([^@\+]*)\+?(.*)@.*`)
var periodsMatch = regexp.MustCompile(`[\.]`)
var postAtMatch = regexp.MustCompile(`[^@]*(@.*)`)
func stripEmail(email string) string {
postAt := postAtMatch.ReplaceAllString(email, `$1`)
prePlus := prePlusMatch.ReplaceAllString(email, `$1`)
strippedEmail := periodsMatch.ReplaceAllString(prePlus, ``) + postAt
return strippedEmail
}
var https = regexp.MustCompile(`(https?://)`)
var trailingSlash = regexp.MustCompile(`(/*$)`)
func stripDomain(domain string) string {
noSlash := trailingSlash.ReplaceAllString(domain, ``)
noProtocol := https.ReplaceAllString(noSlash, ``)
return noProtocol
}
var path = regexp.MustCompile(`(https?://[^/]*)`)
func stripPath(url string) string {
strippedPath := path.ReplaceAllString(url, ``)
return strippedPath
}