From 07ba350d829724cf0b924cf03ae8b20a825cab72 Mon Sep 17 00:00:00 2001
From: celogeek <65178+celogeek@users.noreply.github.com>
Date: Thu, 8 Feb 2024 21:05:27 +0200
Subject: [PATCH] fix comments

---
 internal/converter/converter.go               | 20 +++++++++----------
 .../converter/options/converter_options.go    | 18 ++++++++---------
 .../converter/profiles/converter_profiles.go  |  8 +++-----
 internal/epub/epub.go                         |  6 ++----
 internal/epub/image/epub_image.go             | 12 +++++------
 .../epub_image_filters_autocontrast.go        |  2 +-
 .../epub_image_filters_autocrop.go            |  2 +-
 .../epub_image_filters_cover_title.go         |  6 +++---
 ...ub_image_filters_crop_split_double_page.go |  3 ++-
 .../imagefilters/epub_image_filters_pixel.go  |  3 ++-
 .../imageprocessor/epub_image_processor.go    |  8 +++-----
 internal/epub/options/epub_options.go         |  4 +---
 internal/epub/progress/epub_progress.go       |  4 +---
 internal/epub/templates/epub_templates.go     |  4 +---
 internal/epub/tree/epub_tree.go               |  8 ++++----
 internal/epub/zip/epub_zip.go                 | 13 ++++++------
 internal/epub/zip/epub_zip_image.go           |  2 +-
 internal/sortpath/sortpath.go                 |  2 +-
 18 files changed, 56 insertions(+), 69 deletions(-)

diff --git a/internal/converter/converter.go b/internal/converter/converter.go
index 02792ff..83c0b07 100644
--- a/internal/converter/converter.go
+++ b/internal/converter/converter.go
@@ -30,7 +30,7 @@ type Converter struct {
 	startAt         time.Time
 }
 
-// Create a new parser
+// New Create a new parser
 func New() *Converter {
 	o := options.New()
 	cmd := flag.NewFlagSet("go-comic-converter", flag.ExitOnError)
@@ -61,35 +61,35 @@ func New() *Converter {
 	return conv
 }
 
-// Load default options (config + default)
+// LoadConfig Load default options (config + default)
 func (c *Converter) LoadConfig() error {
 	return c.Options.LoadConfig()
 }
 
-// Create a new section of config
+// AddSection Create a new section of config
 func (c *Converter) AddSection(section string) {
 	c.order = append(c.order, converterOrderSection{value: section})
 }
 
-// Add a string parameter
+// AddStringParam Add a string parameter
 func (c *Converter) AddStringParam(p *string, name string, value string, usage string) {
 	c.Cmd.StringVar(p, name, value, usage)
 	c.order = append(c.order, converterOrderName{value: name, isString: true})
 }
 
-// Add an integer parameter
+// AddIntParam Add an integer parameter
 func (c *Converter) AddIntParam(p *int, name string, value int, usage string) {
 	c.Cmd.IntVar(p, name, value, usage)
 	c.order = append(c.order, converterOrderName{value: name})
 }
 
-// Add an float parameter
+// AddFloatParam Add an float parameter
 func (c *Converter) AddFloatParam(p *float64, name string, value float64, usage string) {
 	c.Cmd.Float64Var(p, name, value, usage)
 	c.order = append(c.order, converterOrderName{value: name})
 }
 
-// Add a boolean parameter
+// AddBoolParam Add a boolean parameter
 func (c *Converter) AddBoolParam(p *bool, name string, value bool, usage string) {
 	c.Cmd.BoolVar(p, name, value, usage)
 	c.order = append(c.order, converterOrderName{value: name})
@@ -159,7 +159,7 @@ func (c *Converter) InitParse() {
 	c.AddBoolParam(&c.Options.Help, "help", false, "Show this help message")
 }
 
-// Customize version of FlagSet.PrintDefaults
+// Usage Customize version of FlagSet.PrintDefaults
 func (c *Converter) Usage(isString bool, f *flag.Flag) string {
 	var b strings.Builder
 	fmt.Fprintf(&b, "  -%s", f.Name) // Two spaces before -; see next two comments.
@@ -274,7 +274,7 @@ func (c *Converter) Parse() {
 	}
 }
 
-// Check parameters
+// Validate Check parameters
 func (c *Converter) Validate() error {
 	// Check input
 	if c.Options.Input == "" {
@@ -391,7 +391,7 @@ func (c *Converter) Validate() error {
 	return nil
 }
 
-// Helper to show usage, err and exit 1
+// Fatal Helper to show usage, err and exit 1
 func (c *Converter) Fatal(err error) {
 	c.Cmd.Usage()
 	fmt.Fprintf(os.Stderr, "\nError: %s\n", err)
diff --git a/internal/converter/options/converter_options.go b/internal/converter/options/converter_options.go
index 3ddd66d..fc7daaf 100644
--- a/internal/converter/options/converter_options.go
+++ b/internal/converter/options/converter_options.go
@@ -1,6 +1,4 @@
-/*
-Manage options with default value from config.
-*/
+// Package options manage options with default value from config.
 package options
 
 import (
@@ -78,7 +76,7 @@ type Options struct {
 	profiles profiles.Profiles
 }
 
-// Initialize default options.
+// New Initialize default options.
 func New() *Options {
 	return &Options{
 		Profile:               "SR",
@@ -185,13 +183,13 @@ func (o *Options) MarshalJSON() ([]byte, error) {
 	return json.Marshal(out)
 }
 
-// Config file: ~/.go-comic-converter.yaml
+// FileName Config file: ~/.go-comic-converter.yaml
 func (o *Options) FileName() string {
 	home, _ := os.UserHomeDir()
 	return filepath.Join(home, ".go-comic-converter.yaml")
 }
 
-// Load config files
+// LoadConfig Load config files
 func (o *Options) LoadConfig() error {
 	f, err := os.Open(o.FileName())
 	if err != nil {
@@ -206,7 +204,7 @@ func (o *Options) LoadConfig() error {
 	return nil
 }
 
-// Get current settings for fields that can be saved
+// ShowConfig Get current settings for fields that can be saved
 func (o *Options) ShowConfig() string {
 	var profileDesc string
 	profile := o.GetProfile()
@@ -295,7 +293,7 @@ func (o *Options) ShowConfig() string {
 	return b.String()
 }
 
-// reset all settings to default value
+// ResetConfig reset all settings to default value
 func (o *Options) ResetConfig() error {
 	New().SaveConfig()
 	return o.LoadConfig()
@@ -311,12 +309,12 @@ func (o *Options) SaveConfig() error {
 	return yaml.NewEncoder(f).Encode(o)
 }
 
-// shortcut to get current profile
+// GetProfile shortcut to get current profile
 func (o *Options) GetProfile() *profiles.Profile {
 	return o.profiles.Get(o.Profile)
 }
 
-// all available profiles
+// AvailableProfiles all available profiles
 func (o *Options) AvailableProfiles() string {
 	return o.profiles.String()
 }
diff --git a/internal/converter/profiles/converter_profiles.go b/internal/converter/profiles/converter_profiles.go
index 466470b..139459e 100644
--- a/internal/converter/profiles/converter_profiles.go
+++ b/internal/converter/profiles/converter_profiles.go
@@ -1,6 +1,4 @@
-/*
-Manage supported profiles for go-comic-converter.
-*/
+// Package profiles manage supported profiles for go-comic-converter.
 package profiles
 
 import (
@@ -17,7 +15,7 @@ type Profile struct {
 
 type Profiles []Profile
 
-// Initialize list of all supported profiles.
+// New Initialize list of all supported profiles.
 func New() Profiles {
 	return []Profile{
 		// High Resolution for Tablet
@@ -68,7 +66,7 @@ func (p Profiles) String() string {
 	return strings.Join(s, "\n")
 }
 
-// Lookup profile by code
+// Get Lookup profile by code
 func (p Profiles) Get(name string) *Profile {
 	for _, profile := range p {
 		if profile.Code == name {
diff --git a/internal/epub/epub.go b/internal/epub/epub.go
index 699f93e..68eb804 100644
--- a/internal/epub/epub.go
+++ b/internal/epub/epub.go
@@ -1,6 +1,4 @@
-/*
-Tools to create EPUB from images.
-*/
+// Package epub Tools to create EPUB from images.
 package epub
 
 import (
@@ -41,7 +39,7 @@ type epubPart struct {
 	Reader *zip.ReadCloser
 }
 
-// initialize EPUB
+// New initialize EPUB
 func New(options *epuboptions.Options) *ePub {
 	uid := uuid.Must(uuid.NewV4())
 	tmpl := template.New("parser")
diff --git a/internal/epub/image/epub_image.go b/internal/epub/image/epub_image.go
index 6b096dc..b8eea96 100644
--- a/internal/epub/image/epub_image.go
+++ b/internal/epub/image/epub_image.go
@@ -1,6 +1,4 @@
-/*
-Image helpers to transform image.
-*/
+// Package epubimage Image helpers to transform image.
 package epubimage
 
 import (
@@ -50,22 +48,22 @@ func (i *Image) PagePath() string {
 	return fmt.Sprintf("Text/%s.xhtml", i.PageKey())
 }
 
-// page path into the EPUB
+// EPUBPagePath page path into the EPUB
 func (i *Image) EPUBPagePath() string {
 	return fmt.Sprintf("OEBPS/%s", i.PagePath())
 }
 
-// key for image
+// ImgKey key for image
 func (i *Image) ImgKey() string {
 	return fmt.Sprintf("img_%d_p%d", i.Id, i.Part)
 }
 
-// image path
+// ImgPath image path
 func (i *Image) ImgPath() string {
 	return fmt.Sprintf("Images/%s.%s", i.ImgKey(), i.Format)
 }
 
-// image path into the EPUB
+// EPUBImgPath image path into the EPUB
 func (i *Image) EPUBImgPath() string {
 	return fmt.Sprintf("OEBPS/%s", i.ImgPath())
 }
diff --git a/internal/epub/imagefilters/epub_image_filters_autocontrast.go b/internal/epub/imagefilters/epub_image_filters_autocontrast.go
index 4406c8e..48c9edf 100644
--- a/internal/epub/imagefilters/epub_image_filters_autocontrast.go
+++ b/internal/epub/imagefilters/epub_image_filters_autocontrast.go
@@ -8,7 +8,7 @@ import (
 	"github.com/disintegration/gift"
 )
 
-// Automatically improve contrast
+// AutoContrast Automatically improve contrast
 func AutoContrast() *autocontrast {
 	return &autocontrast{}
 }
diff --git a/internal/epub/imagefilters/epub_image_filters_autocrop.go b/internal/epub/imagefilters/epub_image_filters_autocrop.go
index 718bcd9..e3929fb 100644
--- a/internal/epub/imagefilters/epub_image_filters_autocrop.go
+++ b/internal/epub/imagefilters/epub_image_filters_autocrop.go
@@ -7,7 +7,7 @@ import (
 	"github.com/disintegration/gift"
 )
 
-// Lookup for margin and crop
+// AutoCrop Lookup for margin and crop
 func AutoCrop(img image.Image, bounds image.Rectangle, cutRatioLeft, cutRatioUp, cutRatioRight, cutRatioBottom int) gift.Filter {
 	return gift.Crop(
 		findMargin(img, bounds, cutRatioOptions{cutRatioLeft, cutRatioUp, cutRatioRight, cutRatioBottom}),
diff --git a/internal/epub/imagefilters/epub_image_filters_cover_title.go b/internal/epub/imagefilters/epub_image_filters_cover_title.go
index f69d9dd..e9dde93 100644
--- a/internal/epub/imagefilters/epub_image_filters_cover_title.go
+++ b/internal/epub/imagefilters/epub_image_filters_cover_title.go
@@ -11,7 +11,7 @@ import (
 	"golang.org/x/image/font/gofont/gomonobold"
 )
 
-// Create a title with the cover image
+// CoverTitle Create a title with the cover image
 func CoverTitle(title string, align string, pctWidth int, pctMargin int, maxFontSize int, borderSize int) gift.Filter {
 	return &coverTitle{title, align, pctWidth, pctMargin, maxFontSize, borderSize}
 }
@@ -25,12 +25,12 @@ type coverTitle struct {
 	borderSize  int
 }
 
-// size is the same as source
+// Bounds size is the same as source
 func (p *coverTitle) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
 	return srcBounds
 }
 
-// blur the src image, and create a box with the title in the middle
+// 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) {
 	draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src)
 	if p.title == "" {
diff --git a/internal/epub/imagefilters/epub_image_filters_crop_split_double_page.go b/internal/epub/imagefilters/epub_image_filters_crop_split_double_page.go
index 4205b0a..2eb7d65 100644
--- a/internal/epub/imagefilters/epub_image_filters_crop_split_double_page.go
+++ b/internal/epub/imagefilters/epub_image_filters_crop_split_double_page.go
@@ -7,7 +7,8 @@ import (
 	"github.com/disintegration/gift"
 )
 
-// Cut a double page in 2 part: left and right.
+// CropSplitDoublePage Cut a double page in 2 part: left and right.
+//
 // This will cut in the middle of the page.
 func CropSplitDoublePage(right bool) gift.Filter {
 	return &cropSplitDoublePage{right}
diff --git a/internal/epub/imagefilters/epub_image_filters_pixel.go b/internal/epub/imagefilters/epub_image_filters_pixel.go
index c8dbff6..a832dde 100644
--- a/internal/epub/imagefilters/epub_image_filters_pixel.go
+++ b/internal/epub/imagefilters/epub_image_filters_pixel.go
@@ -8,7 +8,8 @@ import (
 	"github.com/disintegration/gift"
 )
 
-// Generate a blank pixel 1x1, if the size of the image is 0x0.
+// Pixel Generate a blank pixel 1x1, if the size of the image is 0x0.
+//
 // An image 0x0 is not a valid image, and failed to read.
 func Pixel() gift.Filter {
 	return &pixel{}
diff --git a/internal/epub/imageprocessor/epub_image_processor.go b/internal/epub/imageprocessor/epub_image_processor.go
index c4dedbc..a77e826 100644
--- a/internal/epub/imageprocessor/epub_image_processor.go
+++ b/internal/epub/imageprocessor/epub_image_processor.go
@@ -1,6 +1,4 @@
-/*
-Extract and transform image into a compressed jpeg.
-*/
+// Package epubimageprocessor extract and transform image into a compressed jpeg.
 package epubimageprocessor
 
 import (
@@ -27,7 +25,7 @@ func New(o *epuboptions.Options) *EPUBImageProcessor {
 	return &EPUBImageProcessor{o}
 }
 
-// extract and convert images
+// Load extract and convert images
 func (e *EPUBImageProcessor) Load() (images []*epubimage.Image, err error) {
 	images = make([]*epubimage.Image, 0)
 	imageCount, imageInput, err := e.load()
@@ -300,7 +298,7 @@ func (e *EPUBImageProcessor) Cover16LevelOfGray(bounds image.Rectangle) draw.Ima
 	})
 }
 
-// create a title page with the cover
+// CoverTitleData create a title page with the cover
 func (e *EPUBImageProcessor) CoverTitleData(o *CoverTitleDataOptions) (*epubzip.ZipImage, error) {
 	// Create a blur version of the cover
 	g := gift.New(epubimagefilters.CoverTitle(o.Text, o.Align, o.PctWidth, o.PctMargin, o.MaxFontSize, o.BorderSize))
diff --git a/internal/epub/options/epub_options.go b/internal/epub/options/epub_options.go
index fce707e..17665dc 100644
--- a/internal/epub/options/epub_options.go
+++ b/internal/epub/options/epub_options.go
@@ -1,6 +1,4 @@
-/*
-Options for EPUB creation.
-*/
+// Package epuboptions Options for EPUB creation.
 package epuboptions
 
 import "fmt"
diff --git a/internal/epub/progress/epub_progress.go b/internal/epub/progress/epub_progress.go
index f664f72..84d5f5c 100644
--- a/internal/epub/progress/epub_progress.go
+++ b/internal/epub/progress/epub_progress.go
@@ -1,6 +1,4 @@
-/*
-create a progress bar with custom settings.
-*/
+// Package epubprogress create a progress bar with custom settings.
 package epubprogress
 
 import (
diff --git a/internal/epub/templates/epub_templates.go b/internal/epub/templates/epub_templates.go
index 12cbd52..dd80a40 100644
--- a/internal/epub/templates/epub_templates.go
+++ b/internal/epub/templates/epub_templates.go
@@ -1,6 +1,4 @@
-/*
-Templates use to create xml files of the EPUB.
-*/
+// Package epubtemplates Templates use to create xml files of the EPUB.
 package epubtemplates
 
 import _ "embed"
diff --git a/internal/epub/tree/epub_tree.go b/internal/epub/tree/epub_tree.go
index 8b6fe83..898fb57 100644
--- a/internal/epub/tree/epub_tree.go
+++ b/internal/epub/tree/epub_tree.go
@@ -1,5 +1,5 @@
 /*
-Organize a list of filename with their path into a tree of directories.
+Package epubtree Organize a list of filename with their path into a tree of directories.
 
 Example:
   - A/B/C/D.jpg
@@ -39,12 +39,12 @@ func New() *tree {
 	}}
 }
 
-// root node
+// Root root node
 func (n *tree) Root() *node {
 	return n.Nodes["."]
 }
 
-// add the filename to the tree
+// Add add the filename to the tree
 func (n *tree) Add(filename string) {
 	cn := n.Root()
 	cp := ""
@@ -58,7 +58,7 @@ func (n *tree) Add(filename string) {
 	}
 }
 
-// string version of the tree
+// WriteString string version of the tree
 func (n *node) WriteString(indent string) string {
 	r := strings.Builder{}
 	if indent != "" {
diff --git a/internal/epub/zip/epub_zip.go b/internal/epub/zip/epub_zip.go
index 98809f7..b9d1167 100644
--- a/internal/epub/zip/epub_zip.go
+++ b/internal/epub/zip/epub_zip.go
@@ -1,5 +1,5 @@
 /*
-Helper to write EPUB files.
+Package epubzip Helper to write EPUB files.
 
 We create a zip with the magic EPUB mimetype.
 */
@@ -16,7 +16,7 @@ type EPUBZip struct {
 	wz *zip.Writer
 }
 
-// create a new EPUB
+// New create a new EPUB
 func New(path string) (*EPUBZip, error) {
 	w, err := os.Create(path)
 	if err != nil {
@@ -26,7 +26,7 @@ func New(path string) (*EPUBZip, error) {
 	return &EPUBZip{w, wz}, nil
 }
 
-// close compress pipe and file.
+// Close close compress pipe and file.
 func (e *EPUBZip) Close() error {
 	if err := e.wz.Close(); err != nil {
 		return err
@@ -34,7 +34,8 @@ func (e *EPUBZip) Close() error {
 	return e.w.Close()
 }
 
-// Write mimetype, in a very specific way.
+// WriteMagic Write mimetype, in a very specific way.
+//
 // This will be valid with epubcheck tools.
 func (e *EPUBZip) WriteMagic() error {
 	t := time.Now()
@@ -62,7 +63,7 @@ func (e *EPUBZip) Copy(fz *zip.File) error {
 	return e.wz.Copy(fz)
 }
 
-// Write image. They are already compressed, so we write them down directly.
+// WriteRaw Write image. They are already compressed, so we write them down directly.
 func (e *EPUBZip) WriteRaw(raw *ZipImage) error {
 	m, err := e.wz.CreateRaw(raw.Header)
 	if err != nil {
@@ -72,7 +73,7 @@ func (e *EPUBZip) WriteRaw(raw *ZipImage) error {
 	return err
 }
 
-// Write file. Compressed it using deflate.
+// WriteContent Write file. Compressed it using deflate.
 func (e *EPUBZip) WriteContent(file string, content []byte) error {
 	m, err := e.wz.CreateHeader(&zip.FileHeader{
 		Name:     file,
diff --git a/internal/epub/zip/epub_zip_image.go b/internal/epub/zip/epub_zip_image.go
index 1439687..ad1f0b4 100644
--- a/internal/epub/zip/epub_zip_image.go
+++ b/internal/epub/zip/epub_zip_image.go
@@ -17,7 +17,7 @@ type ZipImage struct {
 	Data   []byte
 }
 
-// create gzip encoded jpeg
+// CompressImage create gzip encoded jpeg
 func CompressImage(filename string, format string, img image.Image, quality int) (*ZipImage, error) {
 	var (
 		data, cdata bytes.Buffer
diff --git a/internal/sortpath/sortpath.go b/internal/sortpath/sortpath.go
index cc9a890..d8425e5 100644
--- a/internal/sortpath/sortpath.go
+++ b/internal/sortpath/sortpath.go
@@ -39,7 +39,7 @@ func (b by) Swap(i, j int) {
 	b.paths[i], b.paths[j] = b.paths[j], b.paths[i]
 }
 
-// use sortpath.By with sort.Sort
+// By use sortpath.By with sort.Sort
 func By(filenames []string, mode int) by {
 	p := [][]part{}
 	for _, filename := range filenames {