shared

package
v0.0.0-...-d10c4ce Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2025 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const LIMITER_KEY = "LIMITER"

LIMITER_KEY is the key in Context used for the limiter

Variables

View Source
var APIUrl = url.URL{
	Scheme: "https",
	Host:   "api.mangadex.org",
}

APIUrl is the default MangaDex API URL

View Source
var DevUrl = url.URL{
	Scheme: "https",
	Host:   "api.mangadex.dev",
}

DevUrl is the MangaDex Dev API URL used in place of APIUrl

View Source
var QueryAPILimiter = rate.NewLimiter(rate.Every(time.Second)/5, 5)

QueryAPILimiter limits the rate that QueryAPI is called

View Source
var QueryImageLimiter = rate.NewLimiter(rate.Every(time.Second)/5, 5)

QueryImageLimiter limits the rate that QueryImage is called

View Source
var UploadsURL = url.URL{
	Scheme: "https",
	Host:   "uploads.mangadex.org",
}

UploadsURL is the MangaDex Uploads URL used when the MDUploads option is true

View Source
var Version string

Version is the current version of this software calculated with debug.ReadBuildInfo

Functions

func AssertEq

func AssertEq[T comparable](t *testing.T, actual, expected T) bool

AssertEq asserts that two values are equal in a test, logging if they are not.

func AssertNeq

func AssertNeq[T comparable](t *testing.T, actual, unexpected T) bool

AssertEq asserts that two values are NOT equal in a test, logging if they are.

func CastOr

func CastOr[T any](v any, or *T) *T

CastOr takes a value to cast and an optional fallback, returning the cast value if it matches or the fallback if it does not.

func QueryAPI

func QueryAPI[T any](
	ctx context.Context,
	queryPath string,
	queryParams url.Values,
) (out T, err error)

QueryAPI is used to fetch data from the MangaDex API.

func QueryImage

func QueryImage(
	ctx context.Context,
	imgUrl *url.URL,
	w io.Writer,
) (err error)

QueryImage is used to fetch an image from the given URL. Only PNG and JPG images are supported, for compatibility with downstream CBZ and EPUB formats.

func ReadOptionsFromEnv

func ReadOptionsFromEnv()

ReadOptionsFromEnv pulls in the configuation options from the environment variables THEN from the .env file (which takes precedence) and loads them into GlobalOptions.

func TestOptions

func TestOptions()

TestOptions sets the options used for testing

func Tr

func Tr(m map[string]string) string

Tr takes a map of translation strings and returns the one matching the language in GlobalOptions OR the special `ja-ro` translation OR the fallback string "Unknown".

func UserAgent

func UserAgent() string

UserAgent constructs the `User-Agent` header from the build information.

func WithDefaultParams

func WithDefaultParams(queryParams url.Values) url.Values

TODO make this more general so it can be used for Chapters

Types

type Options

type Options struct {
	Bind          string     // Address that the HTTP server will bind to
	Host          url.URL    // Host used in generated paths, useful for proxies
	Language      string     // Language to pull chapters for
	Query         url.Values // Default query string parameters
	DataSaver     bool       // Use MD's data saver mode for smaller images
	MDUploads     bool       // Use the MD uploads endpoint instead of MD@Home
	DevApi        bool       // Use the MD dev API
	ExpVars       bool       // Enable the ExpVars endpoint
	GzipResponses bool       // Enable gzipping responses
	LogLevel      slog.Level // The log level
	NoDownload    bool       // Disable downloading images for chapters, used in some tests
	RetryAmount   int        // Number of times to retry when querying the API
}

Options is the list of configuation options for this project.

var GlobalOptions Options

GlobalOptions is the globally available set of options that is currently being used. You should ONLY read from this value and never set it.

Jump to

Keyboard shortcuts

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