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/notifier.go
Julien Riou 0a9ae46d19
Add Telegram Messenger notifications
Signed-off-by: Julien Riou <julien@riou.xyz>
2021-03-24 09:35:37 +01:00

26 lines
698 B
Go

package main
import (
"fmt"
"time"
)
// Notifier interface to notify when a product becomes available or is sold out again
type Notifier interface {
NotifyWhenAvailable(string, string, float64, string, string) error
NotifyWhenNotAvailable(string, time.Duration) error
}
// formatPrice using internationalization rules
// euro sign is placed after the value
// default the currency, or symbol if applicable, is placed before the value
func formatPrice(value float64, currency string) string {
switch {
case currency == "EUR":
return fmt.Sprintf("%.2f€", value)
case currency == "USD":
return fmt.Sprintf("$%.2f", value)
default:
return fmt.Sprintf("%s%.2f", currency, value)
}
}