Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func CurrencyExchangeHandler(/*irccon *irc.Connection,*/ value string)(){
- var code string
- //Work out currency
- switch{
- case strings.HasPrefix(value, "$"):
- code = "USD"
- value = strings.TrimPrefix(value, "$")
- case strings.HasPrefix(value, "£"):
- code = "GBP"
- value = strings.TrimPrefix(value, "£")
- case strings.HasPrefix(value, "€"):
- code = "EUR"
- value = strings.TrimPrefix(value, "€")
- case strings.HasPrefix(value, "Fr."):
- code = "CHF"
- value = strings.TrimPrefix(value, "Fr.")
- case strings.HasPrefix(value, "SFr."):
- code = "CHF"
- value = strings.TrimPrefix(value, "SFr.")
- case strings.HasPrefix(value, "FS"):
- code = "CHF"
- value = strings.TrimPrefix(value, "FS")
- }
- if code == "" {
- log.Fatal(errors.New("Currency not recognised"))
- }
- value = strings.Trim(value, " ")//trim white space
- value_flt, err := str_to_flt(value)
- USD, err := ConvertCurrency(code, "USD", value_flt)
- if err != nil {
- log.Fatal(err)
- }
- GBP, err := ConvertCurrency(code, "GBP", value_flt)
- if err != nil {
- log.Fatal(err)
- }
- EUR, err := ConvertCurrency(code, "EUR", value_flt)
- if err != nil {
- log.Fatal(err)
- }
- CHF, err := ConvertCurrency(code, "CHF", value_flt)
- if err != nil {
- log.Fatal(err)
- }
- fmt.Printf("$%v\t£%v\t€%v\tFS%v\n", USD, GBP, EUR, CHF)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement