From 1c7732cf32274fb66befc9553128151b4bc7ccd9 Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Sun, 3 Nov 2019 15:46:00 -0800 Subject: [PATCH] Add string methods --- lib/application/app.go | 2 +- lib/bucket/bucket.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/application/app.go b/lib/application/app.go index 0197505..67a87c9 100644 --- a/lib/application/app.go +++ b/lib/application/app.go @@ -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 } diff --git a/lib/bucket/bucket.go b/lib/bucket/bucket.go index 2077fca..bb8c4bb 100644 --- a/lib/bucket/bucket.go +++ b/lib/bucket/bucket.go @@ -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) +}