diff --git a/internal/epub/progress/epub_progress.go b/internal/epubprogress/epubprogress.go similarity index 88% rename from internal/epub/progress/epub_progress.go rename to internal/epubprogress/epubprogress.go index f664f72..b48b658 100644 --- a/internal/epub/progress/epub_progress.go +++ b/internal/epubprogress/epubprogress.go @@ -4,6 +4,7 @@ create a progress bar with custom settings. package epubprogress import ( + "encoding/json" "fmt" "os" "time" @@ -20,18 +21,21 @@ type Options struct { TotalJob int } -type EpubProgress interface { +type epubProgress interface { Add(num int) error Close() error } -func New(o Options) EpubProgress { +func New(o Options) epubProgress { if o.Quiet { return progressbar.DefaultSilent(int64(o.Max)) } if o.Json { - return newEpubProgressJson(o) + return &epubProgressJson{ + o: o, + e: json.NewEncoder(os.Stdout), + } } fmtJob := fmt.Sprintf("%%0%dd", len(fmt.Sprint(o.TotalJob))) diff --git a/internal/epub/progress/epub_progress_json.go b/internal/epubprogress/epubprogress_json.go similarity index 64% rename from internal/epub/progress/epub_progress_json.go rename to internal/epubprogress/epubprogress_json.go index fc4a46c..4b52037 100644 --- a/internal/epub/progress/epub_progress_json.go +++ b/internal/epubprogress/epubprogress_json.go @@ -2,23 +2,15 @@ package epubprogress import ( "encoding/json" - "os" ) -type EpubProgressJson struct { +type epubProgressJson struct { o Options e *json.Encoder current int } -func newEpubProgressJson(o Options) EpubProgress { - return &EpubProgressJson{ - o: o, - e: json.NewEncoder(os.Stdout), - } -} - -func (p *EpubProgressJson) Add(num int) error { +func (p *epubProgressJson) Add(num int) error { p.current += num p.e.Encode(map[string]any{ "type": "progress", @@ -37,6 +29,6 @@ func (p *EpubProgressJson) Add(num int) error { return nil } -func (p *EpubProgressJson) Close() error { +func (p *epubProgressJson) Close() error { return nil }