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

25 lines
482 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
import "fmt"
type product struct {
title string
price money
}
2019-09-27 19:09:07 +03:00
// String makes the product an fmt.Stringer
2019-09-01 21:57:52 +03:00
func (p *product) String() string {
return fmt.Sprintf("%-15s: %s", p.title, p.price)
}
func (p *product) discount(ratio float64) {
p.price *= money(1 - ratio)
}