config

package
v1.60.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2021 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package config abstracts all program configuration.

Index

Constants

View Source
const (
	MhlNone int = iota
	MhlEpub
	MhlMobi
	MhlUnknown
)

Internal constants defining if program was invoked via MyHomeLib wrappers.

View Source
const (
	VigBeforeTitle = "before_title"
	VigAfterTitle  = "after_title"
	VigChapterEnd  = "chapter_end"
)

names of supported vignettes

Variables

This section is empty.

Functions

func CleanFileName

func CleanFileName(in string) string

CleanFileName removes not allowed characters form file name.

func EnableColorOutput

func EnableColorOutput(stream *os.File) bool

EnableColorOutput checks if colorized output is possible.

func FindConverter

func FindConverter(_ string) string

FindConverter - used on Windows to support myhomelib

Types

type AuthorName

type AuthorName struct {
	First  string `json:"first_name"`
	Middle string `json:"middle_name"`
	Last   string `json:"last_name"`
}

AuthorName is parsed author name from book metainfo.

func (*AuthorName) String

func (a *AuthorName) String() string

type Config

type Config struct {
	// Internal implementation - keep it local, could be replaced
	Path string

	// Actual configuration used everywhere - immutable
	ConsoleLogger Logger
	FileLogger    Logger
	Doc           Doc
	SMTPConfig    SMTPConfig
	Fb2Mobi       Fb2Mobi
	Fb2Epub       Fb2Epub
	Overwrites    map[string]MetaInfo
	// contains filtered or unexported fields
}

Config keeps all configuration values.

func BuildConfig

func BuildConfig(fnames ...string) (*Config, error)

BuildConfig loads configuration.

func (*Config) GetActualBytes

func (conf *Config) GetActualBytes() ([]byte, error)

GetActualBytes returns actual configuration, including fields initialized by default.

func (*Config) GetBytes

func (conf *Config) GetBytes() ([]byte, error)

GetBytes returns configuration the way it was read from various sources, before unmarshaling.

func (*Config) GetKindlegenPath

func (conf *Config) GetKindlegenPath() (string, error)

GetKindlegenPath provides platform specific path to the kindlegen executable.

func (*Config) GetOverwrite

func (conf *Config) GetOverwrite(name string) *MetaInfo

GetOverwrite returns pointer to information to be used instead of parsed data.

func (*Config) GetTransformation

func (conf *Config) GetTransformation(name string) *Transformation

GetTransformation returns pointer to named text transformation of nil if none eavailable.

func (*Config) PrepareLog

func (conf *Config) PrepareLog() (*zap.Logger, error)

PrepareLog returns our standard logger. It prepares zap logger for use by the program.

type Doc

type Doc struct {
	TitleFormat           string   `json:"title_format"`
	AuthorFormat          string   `json:"author_format"`
	AuthorFormatMeta      string   `json:"author_format_meta"`
	AuthorFormatFileName  string   `json:"author_format_file_name"`
	TransliterateMeta     bool     `json:"transliterate_meta"`
	OpenFromCover         bool     `json:"open_from_cover"`
	ChapterPerFile        bool     `json:"chapter_per_file"`
	ChapterLevel          int      `json:"chapter_level"`
	SeqNumPos             int      `json:"series_number_positions"`
	RemovePNGTransparency bool     `json:"remove_png_transparency"`
	ImagesScaleFactor     float64  `json:"images_scale_factor"`
	Stylesheet            string   `json:"style"`
	CharsPerPage          int      `json:"characters_per_page"`
	PagesPerFile          int      `json:"pages_per_file"`
	ChapterDividers       []string `json:"chapter_subtitle_dividers"`
	Hyphenate             bool     `json:"insert_soft_hyphen"`
	NoNBSP                bool     `json:"ignore_nonbreakable_space"`
	UseBrokenImages       bool     `json:"use_broken_images"`
	FileNameFormat        string   `json:"file_name_format"`
	FileNameTransliterate bool     `json:"file_name_transliterate"`
	FixZip                bool     `json:"fix_zip_format"`
	//
	DropCaps struct {
		Create        bool   `json:"create"`
		IgnoreSymbols string `json:"ignore_symbols"`
	} `json:"dropcaps"`
	Notes struct {
		BodyNames []string `json:"body_names"`
		Mode      string   `json:"mode"`
		Renumber  bool     `json:"renumber"`
		Format    string   `json:"link_format"`
	} `json:"notes"`
	Annotation struct {
		Create   bool   `json:"create"`
		AddToToc bool   `json:"add_to_toc"`
		Title    string `json:"title"`
	} `json:"annotation"`
	TOC struct {
		Type              string `json:"type"`
		Title             string `json:"page_title"`
		Placement         string `json:"page_placement"`
		MaxLevel          int    `json:"page_maxlevel"`
		NoTitleChapters   bool   `json:"include_chapters_without_title"`
		BookTitleFromMeta bool   `json:"book_title_from_meta"`
	} `json:"toc"`
	Cover struct {
		Default   bool   `json:"default"`
		ImagePath string `json:"image_path"`
		Width     int    `json:"width"`
		Height    int    `json:"height"`
		Resize    string `json:"resize"`
		Placement string `json:"stamp_placement"`
		Font      string `json:"stamp_font"`
	} `json:"cover"`
	Vignettes struct {
		Create bool                         `json:"create"`
		Images map[string]map[string]string `json:"images"`
	} `json:"vignettes"`
	//
	Transformations map[string]map[string]string `json:"transform"`
	//
	Kindlegen struct {
		Path             string `json:"path"`
		CompressionLevel int    `json:"compression_level"`
		Verbose          bool   `json:"verbose"`
		NoOptimization   bool   `json:"no_mobi_optimization"`
		RemovePersonal   bool   `json:"remove_personal_label"`
		PageMap          string `json:"generate_apnx"`
		ForceASIN        bool   `json:"force_asin_on_azw3"`
	} `json:"kindlegen"`
}

Doc format configuration for book processor.

type Fb2Epub

type Fb2Epub struct {
	OutputFormat string `json:"output_format"`
}

Fb2Epub provides special support for MyHomeLib.

type Fb2Mobi

type Fb2Mobi struct {
	OutputFormat string `json:"output_format"`
	SendToKindle bool   `json:"send_to_kindle"`
}

Fb2Mobi provides special support for MyHomeLib.

type Logger

type Logger struct {
	Level       string `json:"level"`
	Destination string `json:"destination"`
	Mode        string `json:"mode"`
}

Logger configuration for single logger.

type MetaInfo

type MetaInfo struct {
	ID         string        `json:"id"`
	ASIN       string        `json:"asin"`
	Title      string        `json:"title"`
	Lang       string        `json:"language"`
	Genres     []string      `json:"genres"`
	Authors    []*AuthorName `json:"authors"`
	SeqName    string        `json:"sequence"`
	SeqNum     int           `json:"sequence_number"`
	Date       string        `json:"date"`
	CoverImage string        `json:"cover_image"`
}

MetaInfo keeps book meta-info overwrites from configuration.

type SMTPConfig

type SMTPConfig struct {
	DeleteOnSuccess bool   `json:"delete_sent_book"`
	Server          string `json:"smtp_server"`
	Port            int    `json:"smtp_port"`
	User            string `json:"smtp_user"`
	Password        string `json:"smtp_password"`
	From            string `json:"from_mail"`
	To              string `json:"to_mail"`
}

SMTPConfig keeps STK configuration.

func (*SMTPConfig) IsValid

func (c *SMTPConfig) IsValid() bool

IsValid checks if we have enough smtp parameters to attempt sending mail. It does not attempt actual connection.

type Transformation

type Transformation struct {
	From string
	To   string
}

Transformation is used to specify additional text processsing during conversion.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL