@@ -28,17 +28,6 @@ func init() {
2828 }
2929}
3030
31- func composeEmail (ent models.Entity ) string {
32- key , err := ent .K .MarshalJSON ()
33- if err != nil {
34- key = []byte ("unrecognizable key" )
35- }
36- return fmt .Sprintf (`Link to the website: %s
37- Name: %s
38- XPATH: %s
39- Key: %s` , ent .URL , ent .Name , ent .XPATH , key )
40- }
41-
4231// Refresh refreshes prices from datastore
4332func Refresh () {
4433 log .Println ("INFO: Refresh started" )
@@ -61,10 +50,10 @@ func Refresh() {
6150 }
6251 if ent .Options .AlertType == "onChange" && content != last .Price {
6352 subject := fmt .Sprintf ("[%s] <%s> Alert: price changes to %s!" , email .Identity , ent .Name , content )
64- email . Send ( composeEmail ( ent ), subject , ent . Options . Email )
53+ ent . SendEmail ( & subject )
6554 } else if ent .Options .AlertType == "threshold" && ent .Options .Threshold >= float32 (thisP ) {
6655 subject := fmt .Sprintf ("[%s] <%s> Alert: price drops to %s!" , email .Identity , ent .Name , content )
67- email . Send ( composeEmail ( ent ), subject , ent . Options . Email )
56+ ent . SendEmail ( & subject )
6857 }
6958
7059 // update history & save entity
@@ -88,7 +77,7 @@ func Refresh() {
8877 key , _ := ent .K .MarshalJSON ()
8978 log .Printf ("URL: %s\n XPATH: %s\n Key: %s" , ent .URL , ent .XPATH , key )
9079 subject := fmt .Sprintf ("[%s] <%s> Alert: failed to fetch price for reason `%s`!" , email .Identity , ent .Name , content )
91- email . Send ( composeEmail ( ent ), subject , ent . Options . Email )
80+ ent . SendEmail ( & subject )
9281 }
9382 }
9483 }
0 commit comments