Archived
1
0
Fork 0
This repository has been archived on 2024-12-18. You can view files and clone it, but cannot push or open issues or pull requests.
restockbot/utils.go
Julien Riou 40b0ba999a
Remove useless compileRegex function
Signed-off-by: Julien Riou <julien@riou.xyz>
2021-02-27 15:14:21 +01:00

18 lines
474 B
Go

package main
import (
"net/url"
"regexp"
"strings"
)
// ExtractShopName parses a link to extract the hostname, then remove leading www, to build the Shop name
// "https://www.ldlc.com/informatique/pieces-informatique/[...]" -> "ldlc.com"
func ExtractShopName(link string) (name string, err error) {
u, err := url.Parse(link)
if err != nil {
return "", err
}
re := regexp.MustCompile(`^www\.`)
return strings.ToLower(re.ReplaceAllString(u.Hostname(), "")), nil
}