Add string methods

This commit is contained in:
Buddy Sandidge 2019-11-03 15:46:00 -08:00
parent 0943ed42dd
commit 1c7732cf32
2 changed files with 8 additions and 1 deletions

View File

@ -45,7 +45,7 @@ func New(args ...string) (*App, error) {
func (a *App) Run() error {
fmt.Printf("target: %d\n", a.Target)
for i, bucket := range a.Buckets {
fmt.Printf("bucket %d: %d\n", i+1, bucket.Capacity)
fmt.Printf("bucket %d: %s\n", i+1, bucket.String())
}
return nil
}

View File

@ -1,5 +1,7 @@
package bucket
import "fmt"
// Bucket to store volume
type Bucket struct {
// Capacity amount the bucket can store
@ -29,3 +31,8 @@ func (b *Bucket) Pour(target *Bucket) {
target.Volume += availableVolume
}
}
// String gets string representation
func (b *Bucket) String() string {
return fmt.Sprintf("%dvol/%dcap", b.Volume, b.Capacity)
}