Files
learngo/interfaces/09-stringer/product.go
2019-09-01 22:05:09 +03:00

25 lines
476 B
Go

// 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
}
// product satisfies the fmt.Stringer
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)
}