imageopt

package
v0.1.0-alpha.21 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package imageopt provides the Node-free GoBeyond runtime image optimizer.

This package is AWS-free by design: it owns the Loader interface, the disk source, the HTTP handler, and the resize/re-encode path. The S3-backed source lives in the nested module github.com/Origens-Dev/gobeyond/imageopt/s3, so only deployments that read images from S3 pull the AWS SDK into their module graph.

Index

Constants

View Source
const (
	// Route is the same-site runtime image optimization endpoint.
	Route = "/_gobeyond/image"

	// ImageSourceBucketEnv and ImageSourcePrefixEnv configure production S3
	// source loading. GOBEYOND_STATIC_DIR takes precedence for local development.
	ImageSourceBucketEnv = "GOBEYOND_IMAGE_SOURCE_BUCKET"
	ImageSourcePrefixEnv = "GOBEYOND_IMAGE_SOURCE_PREFIX"
)

Variables

View Source
var (
	ErrInvalidSource = errors.New("invalid same-site image source")
	ErrNotFound      = errors.New("image source not found")
)
View Source
var DefaultWidths = []int{16, 32, 48, 64, 96, 128, 256, 384, 640, 750, 828, 1080, 1200, 1920, 2048, 3840}

DefaultWidths bounds the variants the runtime will generate.

Functions

func DiskRootFromEnvironment

func DiskRootFromEnvironment(diskRoot string) (root string, ok bool)

DiskRootFromEnvironment resolves the disk image source: diskRoot when set, otherwise GOBEYOND_STATIC_DIR. ok is false when neither is configured.

func Handler

func Handler(loader Loader) http.Handler

Handler returns an HTTP handler for Route.

func S3SourceFromEnvironment

func S3SourceFromEnvironment() (configured bool, err error)

S3SourceFromEnvironment reports whether a complete, valid S3 image source is configured. It errors when the bucket and prefix disagree about being set or when the prefix is unsafe, so the imageopt/s3 module and AWS-free builds report the same misconfiguration.

func ValidatePrefix

func ValidatePrefix(prefix string) (string, error)

ValidatePrefix normalizes a storage prefix, rejecting traversal and empty segments. It is exported for out-of-package Loader implementations.

func ValidateSource

func ValidateSource(source string) (string, error)

ValidateSource normalizes a same-site image source into a safe relative path. Loader implementations outside this package (e.g. imageopt/s3) must call it before touching any storage.

Types

type DiskLoader

type DiskLoader struct {
	Root string
}

DiskLoader reads static files beneath Root.

func (DiskLoader) Open

func (loader DiskLoader) Open(_ context.Context, source string) (io.ReadCloser, error)

Open securely resolves source beneath the configured static root.

type Loader

type Loader interface {
	Open(context.Context, string) (io.ReadCloser, error)
}

Loader opens a same-site static path. Implementations must not interpret it as a remote URL.

func NewLoaderFromEnvironment

func NewLoaderFromEnvironment(_ context.Context, diskRoot string) (Loader, error)

NewLoaderFromEnvironment selects a disk source when diskRoot (or GOBEYOND_STATIC_DIR) is set, and reports no loader when nothing is configured. This package is deliberately AWS-free: S3-backed sources live in the nested github.com/Origens-Dev/gobeyond/imageopt/s3 module, whose s3.NewLoaderFromEnvironment adds the S3 branch to this same environment contract.

Directories

Path Synopsis
s3 module

Jump to

Keyboard shortcuts

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