Files
learngo/interfaces/12-marshaler/product.go

28 lines
653 B
Go
Raw Permalink Normal View History

2019-08-27 15:21:17 +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-08-27 15:21:17 +03:00
package main
2019-10-17 14:11:51 +03:00
import (
"fmt"
)
2019-08-27 15:21:17 +03:00
type product struct {
2019-10-17 14:11:51 +03:00
Title string `json:"title"`
Price money `json:"price"`
2019-10-21 15:21:34 +03:00
Released timestamp `json:"released"`
2019-08-27 15:21:17 +03:00
}
2019-10-17 14:11:51 +03:00
func (p *product) String() string {
return fmt.Sprintf("%s: %s (%s)", p.Title, p.Price, p.Released)
2019-08-27 15:21:17 +03:00
}
2019-10-17 14:11:51 +03:00
func (p *product) discount(ratio float64) {
p.Price *= money(1 - ratio)
2019-08-27 15:21:17 +03:00
}