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
- Variables
- func DiskRootFromEnvironment(diskRoot string) (root string, ok bool)
- func Handler(loader Loader) http.Handler
- func S3SourceFromEnvironment() (configured bool, err error)
- func ValidatePrefix(prefix string) (string, error)
- func ValidateSource(source string) (string, error)
- type DiskLoader
- type Loader
Constants ¶
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 ¶
var ( ErrInvalidSource = errors.New("invalid same-site image source") ErrNotFound = errors.New("image source not found") )
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 ¶
DiskRootFromEnvironment resolves the disk image source: diskRoot when set, otherwise GOBEYOND_STATIC_DIR. ok is false when neither is configured.
func S3SourceFromEnvironment ¶
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 ¶
ValidatePrefix normalizes a storage prefix, rejecting traversal and empty segments. It is exported for out-of-package Loader implementations.
func ValidateSource ¶
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 ¶
Loader opens a same-site static path. Implementations must not interpret it as a remote URL.
func NewLoaderFromEnvironment ¶
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.