Created
June 10, 2019 16:49
-
-
Save mottet-dev/9d1d6858bd3b245cfb411fa0cbf1ad1a to your computer and use it in GitHub Desktop.
PriceFormat - Go Colly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package utils | |
import "regexp" | |
func FormatPrice(price *string) { | |
r := regexp.MustCompile(`\$(\d+(\.\d+)?).*$`) | |
newPrices := r.FindStringSubmatch(*price) | |
if len(newPrices) > 1 { | |
*price = newPrices[1] | |
} else { | |
*price = "Unknown" | |
} | |
} | |
func FormatStars(stars *string) { | |
if len(*stars) >= 3 { | |
*stars = (*stars)[0:3] | |
} else { | |
*stars = "Unknown" | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment