Files
learngo/interfaces/10-stringer/product.go

27 lines
483 B
Go
Raw Normal View History

2019-09-01 21:57:52 +03:00
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
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)
}