Documentation
¶
Index ¶
- Constants
- Variables
- func AssertEq[T comparable](t *testing.T, actual, expected T) bool
- func AssertNeq[T comparable](t *testing.T, actual, unexpected T) bool
- func CastOr[T any](v any, or *T) *T
- func QueryAPI[T any](ctx context.Context, queryPath string, queryParams url.Values) (out T, err error)
- func QueryImage(ctx context.Context, imgUrl *url.URL, w io.Writer) (err error)
- func ReadOptionsFromEnv()
- func TestOptions()
- func Tr(m map[string]string) string
- func UserAgent() string
- func WithDefaultParams(queryParams url.Values) url.Values
- type Options
Constants ¶
const LIMITER_KEY = "LIMITER"
LIMITER_KEY is the key in Context used for the limiter
Variables ¶
var APIUrl = url.URL{
Scheme: "https",
Host: "api.mangadex.org",
}
APIUrl is the default MangaDex API URL
var DevUrl = url.URL{
Scheme: "https",
Host: "api.mangadex.dev",
}
DevUrl is the MangaDex Dev API URL used in place of APIUrl
var QueryAPILimiter = rate.NewLimiter(rate.Every(time.Second)/5, 5)
QueryAPILimiter limits the rate that QueryAPI is called
var QueryImageLimiter = rate.NewLimiter(rate.Every(time.Second)/5, 5)
QueryImageLimiter limits the rate that QueryImage is called
var UploadsURL = url.URL{
Scheme: "https",
Host: "uploads.mangadex.org",
}
UploadsURL is the MangaDex Uploads URL used when the MDUploads option is true
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 ¶
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 ¶
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 Tr ¶
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".
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.