28 lines
598 B
Go
Raw Permalink Normal View History

2019-09-01 21:57:52 +03:00
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
2019-10-30 19:34:44 +03:00
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus
2019-09-01 21:57:52 +03:00
package main
2019-10-17 14:11:51 +03:00
import (
"fmt"
)
2019-09-01 21:57:52 +03:00
type product struct {
2019-10-17 14:11:51 +03:00
title string
price money
released timestamp
2019-09-01 21:57:52 +03:00
}
func (p *product) String() string {
2019-10-17 14:11:51 +03:00
return fmt.Sprintf("%s: %s (%s)", p.title, p.price, p.released)
2019-09-01 21:57:52 +03:00
}
func (p *product) discount(ratio float64) {
p.price *= money(1 - ratio)
}