Documentation
¶
Index ¶
- Variables
- func TargetWidths(minWidth int, maxWidth int, tolerance float64) []int
- type BuilderOption
- type IxParam
- type SrcsetOption
- type SrcsetOpts
- type URLBuilder
- func (b *URLBuilder) CreateSrcset(path string, params []IxParam, options ...SrcsetOption) string
- func (b *URLBuilder) CreateSrcsetFromWidths(path string, params []IxParam, widths []int) string
- func (b *URLBuilder) CreateURL(path string, params ...IxParam) string
- func (b *URLBuilder) Domain() string
- func (b *URLBuilder) Scheme() string
- func (b *URLBuilder) SetToken(token string)
- func (b *URLBuilder) SetUseHTTPS(useHTTPS bool)
- func (b *URLBuilder) SetUseLibParam(useLibParam bool)
- func (b *URLBuilder) UseHTTPS() bool
Constants ¶
This section is empty.
Variables ¶
var DefaultWidths = []int{
100, 116, 135, 156,
181, 210, 244, 283,
328, 380, 441, 512,
594, 689, 799, 927,
1075, 1247, 1446, 1678,
1946, 2257, 2619, 3038,
3524, 4087, 4741, 5500,
6380, 7401, 8192}
DefaultWidths is an array of image widths generated by calling TargetWidths(100, 8192, 0.08). These defaults are quite good, cover a wide range of widths, and are easy to start with.
Functions ¶
func TargetWidths ¶
TargetWidths creates an array of integer image widths. The image widths begin at the minWidth value and end at the maxWidth value––with a defaultTolerance amount of tolerable image width-variance between them.
Types ¶
type BuilderOption ¶
type BuilderOption func(b *URLBuilder)
BuilderOption provides a convenient interface for supplying URLBuilder options to the NewURLBuilder constructor. See WithToken, WithHTTPS, etc. for more details.
func WithHTTPS ¶
func WithHTTPS(useHTTPS bool) BuilderOption
WithHTTPS returns a BuilderOption that NewURLBuilder consumes. The constructor uses this closure to set the URLBuilder's useHTTPS attribute.
func WithLibParam ¶
func WithLibParam(useLibParam bool) BuilderOption
WithLibParam returns a BuilderOption that NewURLBuilder consumes. The constructor uses this closure to set the URLBuilder's useLibParam attribute.
func WithToken ¶
func WithToken(token string) BuilderOption
WithToken returns a BuilderOption that NewURLBuilder consumes. The constructor uses this closure to set the URLBuilder's token attribute.
type IxParam ¶
IxParam seeks to improve the ergonomics of setting url.Values. For instance, without IxParam, caller's would need to write: url.Values{"w": []string{"480"}, "auto": []string{"format", "compress"}} However, by employing this functional type we can write: []IxParam{Param("w", "480"), Param("auto", "format", "compress")}
type SrcsetOption ¶
type SrcsetOption func(opt *SrcsetOpts)
func WithMaxWidth ¶
func WithMaxWidth(maxWidth int) SrcsetOption
func WithMinWidth ¶
func WithMinWidth(minWidth int) SrcsetOption
func WithTolerance ¶
func WithTolerance(tolerance float64) SrcsetOption
func WithVariableQuality ¶
func WithVariableQuality(variableQuality bool) SrcsetOption
type SrcsetOpts ¶
type SrcsetOpts struct {
// contains filtered or unexported fields
}
type URLBuilder ¶
type URLBuilder struct {
// contains filtered or unexported fields
}
URLBuilder facilitates the building of imgix URLs.
func NewURLBuilder ¶
func NewURLBuilder(domain string, options ...BuilderOption) URLBuilder
NewURLBuilder creates a new URLBuilder with the given domain, with HTTPS enabled.
func (*URLBuilder) CreateSrcset ¶
func (b *URLBuilder) CreateSrcset( path string, params []IxParam, options ...SrcsetOption) string
CreateSrcset creates a srcset attribute string. Given a path, set of IxParam parameters, and a set of SrcsetOptions, this function infers which kind of srcset attribute to create.
If the params contain a width parameter or both height and aspect ratio parameters, a fixed-width srcset attribute will be created. This fixed-width srcset attribute will be dpr-based and have variable quality enabled by default. Variable quality can be disabled by passing WithVariableQuality(false).
Otherwise if no explicit width, height, or aspect ratio were found this function will create a fluid-width srcset attribute wherein each URL (or image candidate string) is described by a width in the specified width-range.
func (*URLBuilder) CreateSrcsetFromWidths ¶
func (b *URLBuilder) CreateSrcsetFromWidths(path string, params []IxParam, widths []int) string
CreateSrcsetFromWidths takes a path, a set of params, and an array of widths to create a srcset attribute with width-described URLs (image candidate strings).
func (*URLBuilder) CreateURL ¶
func (b *URLBuilder) CreateURL(path string, params ...IxParam) string
CreateURL creates a URL string given a path and a set of params.
func (*URLBuilder) Domain ¶
func (b *URLBuilder) Domain() string
Domain gets the builder's domain string.
func (*URLBuilder) Scheme ¶
func (b *URLBuilder) Scheme() string
Scheme gets the URL scheme to use, either "http" or "https" (the scheme uses HTTPS by default).
func (*URLBuilder) SetToken ¶
func (b *URLBuilder) SetToken(token string)
SetToken sets the token for this builder. This value will be used to sign URLs created through the builder.
func (*URLBuilder) SetUseHTTPS ¶
func (b *URLBuilder) SetUseHTTPS(useHTTPS bool)
SetUseHTTPS sets a builder's useHTTPS field to true or false. Setting useHTTPS to false forces the builder to use HTTP.
func (*URLBuilder) SetUseLibParam ¶
func (b *URLBuilder) SetUseLibParam(useLibParam bool)
SetUseLibParam toggles the library param on and off. If useLibParam is set to true, the ixlib param will be toggled on. Otherwise, if useLibParam is set to false, the ixlib param will be toggled off and will not appear in the final URL.
func (*URLBuilder) UseHTTPS ¶
func (b *URLBuilder) UseHTTPS() bool
UseHTTPS returns whether HTTPS or HTTP should be used.