From 139acd864b84e551fff216ce0f7180fac39b05cc Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Fri, 9 Feb 2024 10:46:20 +0200 Subject: [PATCH] fix naming --- internal/epub/epub.go | 10 +++--- internal/epub/image/epub_image.go | 2 +- .../epub_image_filters_cover_title.go | 2 +- .../imagefilters/epub_image_filters_pixel.go | 2 +- .../imageprocessor/epub_image_processor.go | 34 +++++++++---------- .../epub_image_processor_loader.go | 2 +- internal/epub/progress/epub_progress_json.go | 8 ++--- .../epub/templates/epub_templates_content.go | 4 +-- internal/epub/zip/epub_zip_storage_image.go | 24 ++++++------- internal/sortpath/sortpath.go | 2 +- internal/sortpath/sortpath_parser.go | 6 ++-- main.go | 8 ++--- 12 files changed, 52 insertions(+), 52 deletions(-) diff --git a/internal/epub/epub.go b/internal/epub/epub.go index 68eb804..de222e3 100644 --- a/internal/epub/epub.go +++ b/internal/epub/epub.go @@ -197,7 +197,7 @@ func (e *ePub) writeTitleImage(wz *epubzip.EPUBZip, img *epubimage.Image, title } // extract image and split it into part -func (e *ePub) getParts() (parts []*epubPart, imgStorage *epubzip.EPUBZipStorageImageReader, err error) { +func (e *ePub) getParts() (parts []*epubPart, imgStorage *epubzip.StorageImageReader, err error) { images, err := e.imageProcessor.Load() if err != nil { @@ -226,7 +226,7 @@ func (e *ePub) getParts() (parts []*epubPart, imgStorage *epubzip.EPUBZipStorage return parts, nil, nil } - imgStorage, err = epubzip.NewEPUBZipStorageImageReader(e.ImgStorage()) + imgStorage, err = epubzip.NewStorageImageReader(e.ImgStorage()) if err != nil { return nil, nil, err } @@ -268,17 +268,17 @@ func (e *ePub) getParts() (parts []*epubPart, imgStorage *epubzip.EPUBZipStorage // create a tree from the directories. // // this is used to simulate the toc. -func (e *ePub) getTree(images []*epubimage.Image, skip_files bool) string { +func (e *ePub) getTree(images []*epubimage.Image, skipFiles bool) string { t := epubtree.New() for _, img := range images { - if skip_files { + if skipFiles { t.Add(img.Path) } else { t.Add(filepath.Join(img.Path, img.Name)) } } c := t.Root() - if skip_files && e.StripFirstDirectoryFromToc && len(c.Children) == 1 { + if skipFiles && e.StripFirstDirectoryFromToc && len(c.Children) == 1 { c = c.Children[0] } diff --git a/internal/epub/image/epub_image.go b/internal/epub/image/epub_image.go index b8eea96..8c3a2ed 100644 --- a/internal/epub/image/epub_image.go +++ b/internal/epub/image/epub_image.go @@ -76,7 +76,7 @@ func (i *Image) ImgStyle(viewWidth, viewHeight int, align string) string { relWidth, relHeight := i.RelSize(viewWidth, viewHeight) marginW, marginH := float64(viewWidth-relWidth)/2, float64(viewHeight-relHeight)/2 - style := []string{} + var style []string style = append(style, fmt.Sprintf("width:%dpx", relWidth)) style = append(style, fmt.Sprintf("height:%dpx", relHeight)) diff --git a/internal/epub/imagefilters/epub_image_filters_cover_title.go b/internal/epub/imagefilters/epub_image_filters_cover_title.go index e9dde93..678b8e0 100644 --- a/internal/epub/imagefilters/epub_image_filters_cover_title.go +++ b/internal/epub/imagefilters/epub_image_filters_cover_title.go @@ -31,7 +31,7 @@ func (p *coverTitle) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangl } // Draw blur the src image, and create a box with the title in the middle -func (p *coverTitle) Draw(dst draw.Image, src image.Image, options *gift.Options) { +func (p *coverTitle) Draw(dst draw.Image, src image.Image, _ *gift.Options) { draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src) if p.title == "" { return diff --git a/internal/epub/imagefilters/epub_image_filters_pixel.go b/internal/epub/imagefilters/epub_image_filters_pixel.go index a832dde..97e20fd 100644 --- a/internal/epub/imagefilters/epub_image_filters_pixel.go +++ b/internal/epub/imagefilters/epub_image_filters_pixel.go @@ -27,7 +27,7 @@ func (p *pixel) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) { return } -func (p *pixel) Draw(dst draw.Image, src image.Image, options *gift.Options) { +func (p *pixel) Draw(dst draw.Image, src image.Image, _ *gift.Options) { if dst.Bounds().Dx() == 1 && dst.Bounds().Dy() == 1 { dst.Set(0, 0, color.White) return diff --git a/internal/epub/imageprocessor/epub_image_processor.go b/internal/epub/imageprocessor/epub_image_processor.go index a77e826..527f1ee 100644 --- a/internal/epub/imageprocessor/epub_image_processor.go +++ b/internal/epub/imageprocessor/epub_image_processor.go @@ -60,7 +60,7 @@ func (e *EPUBImageProcessor) Load() (images []*epubimage.Image, err error) { }) wg := &sync.WaitGroup{} - imgStorage, err := epubzip.NewEPUBZipStorageImageWriter(e.ImgStorage(), e.Image.Format) + imgStorage, err := epubzip.NewStorageImageWriter(e.ImgStorage(), e.Image.Format) if err != nil { bar.Close() return nil, err @@ -279,22 +279,22 @@ type CoverTitleDataOptions struct { func (e *EPUBImageProcessor) Cover16LevelOfGray(bounds image.Rectangle) draw.Image { return image.NewPaletted(bounds, color.Palette{ - color.Gray{0x00}, - color.Gray{0x11}, - color.Gray{0x22}, - color.Gray{0x33}, - color.Gray{0x44}, - color.Gray{0x55}, - color.Gray{0x66}, - color.Gray{0x77}, - color.Gray{0x88}, - color.Gray{0x99}, - color.Gray{0xAA}, - color.Gray{0xBB}, - color.Gray{0xCC}, - color.Gray{0xDD}, - color.Gray{0xEE}, - color.Gray{0xFF}, + color.Gray{}, + color.Gray{Y: 0x11}, + color.Gray{Y: 0x22}, + color.Gray{Y: 0x33}, + color.Gray{Y: 0x44}, + color.Gray{Y: 0x55}, + color.Gray{Y: 0x66}, + color.Gray{Y: 0x77}, + color.Gray{Y: 0x88}, + color.Gray{Y: 0x99}, + color.Gray{Y: 0xAA}, + color.Gray{Y: 0xBB}, + color.Gray{Y: 0xCC}, + color.Gray{Y: 0xDD}, + color.Gray{Y: 0xEE}, + color.Gray{Y: 0xFF}, }) } diff --git a/internal/epub/imageprocessor/epub_image_processor_loader.go b/internal/epub/imageprocessor/epub_image_processor_loader.go index 4405562..bfb359a 100644 --- a/internal/epub/imageprocessor/epub_image_processor_loader.go +++ b/internal/epub/imageprocessor/epub_image_processor_loader.go @@ -208,7 +208,7 @@ func (e *EPUBImageProcessor) loadCbz() (totalImages int, output chan *task, err return } - names := []string{} + var names []string for _, img := range images { names = append(names, img.Name) } diff --git a/internal/epub/progress/epub_progress_json.go b/internal/epub/progress/epub_progress_json.go index fc4a46c..eb691e5 100644 --- a/internal/epub/progress/epub_progress_json.go +++ b/internal/epub/progress/epub_progress_json.go @@ -5,20 +5,20 @@ import ( "os" ) -type EpubProgressJson struct { +type Json struct { o Options e *json.Encoder current int } func newEpubProgressJson(o Options) EpubProgress { - return &EpubProgressJson{ + return &Json{ o: o, e: json.NewEncoder(os.Stdout), } } -func (p *EpubProgressJson) Add(num int) error { +func (p *Json) Add(num int) error { p.current += num p.e.Encode(map[string]any{ "type": "progress", @@ -37,6 +37,6 @@ func (p *EpubProgressJson) Add(num int) error { return nil } -func (p *EpubProgressJson) Close() error { +func (p *Json) Close() error { return nil } diff --git a/internal/epub/templates/epub_templates_content.go b/internal/epub/templates/epub_templates_content.go index 56965fb..861bf7d 100644 --- a/internal/epub/templates/epub_templates_content.go +++ b/internal/epub/templates/epub_templates_content.go @@ -214,7 +214,7 @@ func getSpineAuto(o *ContentOptions) []tag { return fmt.Sprintf("%s layout-blank", getSpread(false)) } - spine := []tag{} + var spine []tag if o.HasTitlePage { if !o.ImageOptions.AppleBookCompatibility { spine = append(spine, @@ -255,7 +255,7 @@ func getSpineAuto(o *ContentOptions) []tag { } func getSpinePortrait(o *ContentOptions) []tag { - spine := []tag{} + var spine []tag if o.HasTitlePage { spine = append(spine, tag{"itemref", tagAttrs{"idref": "page_title"}, ""}, diff --git a/internal/epub/zip/epub_zip_storage_image.go b/internal/epub/zip/epub_zip_storage_image.go index 7073315..50c3c7f 100644 --- a/internal/epub/zip/epub_zip_storage_image.go +++ b/internal/epub/zip/epub_zip_storage_image.go @@ -7,23 +7,23 @@ import ( "sync" ) -type EPUBZipStorageImageWriter struct { +type StorageImageWriter struct { fh *os.File fz *zip.Writer format string mut *sync.Mutex } -func NewEPUBZipStorageImageWriter(filename string, format string) (*EPUBZipStorageImageWriter, error) { +func NewStorageImageWriter(filename string, format string) (*StorageImageWriter, error) { fh, err := os.Create(filename) if err != nil { return nil, err } fz := zip.NewWriter(fh) - return &EPUBZipStorageImageWriter{fh, fz, format, &sync.Mutex{}}, nil + return &StorageImageWriter{fh, fz, format, &sync.Mutex{}}, nil } -func (e *EPUBZipStorageImageWriter) Close() error { +func (e *StorageImageWriter) Close() error { if err := e.fz.Close(); err != nil { e.fh.Close() return err @@ -31,7 +31,7 @@ func (e *EPUBZipStorageImageWriter) Close() error { return e.fh.Close() } -func (e *EPUBZipStorageImageWriter) Add(filename string, img image.Image, quality int) error { +func (e *StorageImageWriter) Add(filename string, img image.Image, quality int) error { zipImage, err := CompressImage(filename, e.format, img, quality) if err != nil { return err @@ -51,7 +51,7 @@ func (e *EPUBZipStorageImageWriter) Add(filename string, img image.Image, qualit return nil } -type EPUBZipStorageImageReader struct { +type StorageImageReader struct { filename string fh *os.File fz *zip.Reader @@ -59,7 +59,7 @@ type EPUBZipStorageImageReader struct { files map[string]*zip.File } -func NewEPUBZipStorageImageReader(filename string) (*EPUBZipStorageImageReader, error) { +func NewStorageImageReader(filename string) (*StorageImageReader, error) { fh, err := os.Open(filename) if err != nil { return nil, err @@ -76,14 +76,14 @@ func NewEPUBZipStorageImageReader(filename string) (*EPUBZipStorageImageReader, for _, z := range fz.File { files[z.Name] = z } - return &EPUBZipStorageImageReader{filename, fh, fz, files}, nil + return &StorageImageReader{filename, fh, fz, files}, nil } -func (e *EPUBZipStorageImageReader) Get(filename string) *zip.File { +func (e *StorageImageReader) Get(filename string) *zip.File { return e.files[filename] } -func (e *EPUBZipStorageImageReader) Size(filename string) uint64 { +func (e *StorageImageReader) Size(filename string) uint64 { img := e.Get(filename) if img != nil { return img.CompressedSize64 + 30 + uint64(len(img.Name)) @@ -91,10 +91,10 @@ func (e *EPUBZipStorageImageReader) Size(filename string) uint64 { return 0 } -func (e *EPUBZipStorageImageReader) Close() error { +func (e *StorageImageReader) Close() error { return e.fh.Close() } -func (e *EPUBZipStorageImageReader) Remove() error { +func (e *StorageImageReader) Remove() error { return os.Remove(e.filename) } diff --git a/internal/sortpath/sortpath.go b/internal/sortpath/sortpath.go index d8425e5..fc27038 100644 --- a/internal/sortpath/sortpath.go +++ b/internal/sortpath/sortpath.go @@ -41,7 +41,7 @@ func (b by) Swap(i, j int) { // By use sortpath.By with sort.Sort func By(filenames []string, mode int) by { - p := [][]part{} + var p [][]part for _, filename := range filenames { p = append(p, parse(filename, mode)) } diff --git a/internal/sortpath/sortpath_parser.go b/internal/sortpath/sortpath_parser.go index c05c50c..7b328e0 100644 --- a/internal/sortpath/sortpath_parser.go +++ b/internal/sortpath/sortpath_parser.go @@ -8,7 +8,7 @@ import ( ) // Strings follow with numbers like: s1, s1.2, s2-3, ... -var split_path_regex = regexp.MustCompile(`^(.*?)(\d+(?:\.\d+)?)(?:-(\d+(?:\.\d+)?))?$`) +var splitPathRegex = regexp.MustCompile(`^(.*?)(\d+(?:\.\d+)?)(?:-(\d+(?:\.\d+)?))?$`) type part struct { fullname string @@ -31,7 +31,7 @@ func (a part) compare(b part) float64 { // separate from the string the number part. func parsePart(p string) part { - r := split_path_regex.FindStringSubmatch(p) + r := splitPathRegex.FindStringSubmatch(p) if len(r) == 0 { return part{p, p, 0} } @@ -51,7 +51,7 @@ func parse(filename string, mode int) []part { ext := filepath.Ext(name) name = name[0 : len(name)-len(ext)] - f := []part{} + var f []part for _, p := range strings.Split(pathname, string(filepath.Separator)) { if mode > 0 { // alphanumeric for path f = append(f, parsePart(p)) diff --git a/main.go b/main.go index 5299123..7ae381d 100644 --- a/main.go +++ b/main.go @@ -43,7 +43,7 @@ func main() { fmt.Fprintln(os.Stderr, "failed to fetch the latest version") os.Exit(1) } - latest_version := v.Versions[0] + latestVersion := v.Versions[0] fmt.Fprintf(os.Stderr, `go-comic-converter Path : %s @@ -57,9 +57,9 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s bi.Main.Path, bi.Main.Sum, bi.Main.Version, - latest_version.Original(), - latest_version.Segments()[0], - latest_version.Original(), + latestVersion.Original(), + latestVersion.Segments()[0], + latestVersion.Original(), ) return }