types

package
v0.0.0-...-be3a50c Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExprProductBasePath = "productBasePath"
	ExprGeonames        = "geonames"
	ExprLocalization    = "localization"
	ExprProductInfo     = "productInfo"
)
View Source
const (
	ObjectPreview      = "preview"
	ObjectTarget       = "target"
	ObjectDynamicInput = "dynamic_input"
	// ObjectNotYetAssigned represents a special case where
	// we don't have enough information yet to classify the object.
	ObjectNotYetAssigned = "not_yet_assigned"
)
View Source
const (
	EventReset   = "Reset"
	EventCreated = "ObjectCreated"
	EventRemoved = "ObjectRemoved"
)

Variables

View Source
var (
	ErrImageNotFound = errors.New("image not found")
)
View Source
var ExprFunctions = []expr.Option{

	expr.Function(
		"_call",
		func(params ...any) (any, error) {
			t0 := time.Now()
			defer func() {
				logger.Tracef("[expr] _call(%q) took %s", params[0], time.Since(t0))
			}()

			res, err := ExprCall(params[0].(string), params[1].(ExprEnv))
			return res, wrapErr("_call", err)
		},
		new(func(exprName string) (any, error)),
		new(func(exprName string, env ExprEnv) (any, error)),
	),

	expr.Function(
		"_exist",
		func(params ...any) (any, error) {
			t0 := time.Now()
			defer func() {
				logger.Tracef("[expr] _exist(%q) took %s", params[0], time.Since(t0))
			}()

			file, err := fileFromSelector(params[0], params[1])
			if err != nil {
				return false, wrapErr("_exist", err)
			}

			res, err := ExprExist(file.CacheKey)
			return res, wrapErr("_exist", err)
		},
		new(func(fileSelector string) (bool, error)),
		new(func(fileSelector string, env ExprEnv) (bool, error)),
	),

	expr.Function(
		"_jq",
		func(params ...any) (any, error) {
			t0 := time.Now()
			defer func() {
				logger.Tracef("[expr] _jq(%q, ...) took %s", params[1], time.Since(t0))
			}()

			file, err := fileFromSelector(params[1], params[3])
			if err != nil {
				return nil, wrapErr("_jq", err)
			}

			res, err := ExprJQ(params[0].(context.Context), file.CacheKey, params[2].(string))
			return res, wrapErr("_jq", err)
		},
		new(func(ctx context.Context, fileSelector string, filter string) (any, error)),
		new(func(ctx context.Context, fileSelector string, filter string, env ExprEnv) (any, error)),
	),

	expr.Function(
		"_loadJSON",
		func(params ...any) (any, error) {
			t0 := time.Now()
			defer func() {
				logger.Tracef("[expr] _loadJSON(%q) took %s", params[0], time.Since(t0))
			}()

			file, err := fileFromSelector(params[0], params[1])
			if err != nil {
				return nil, wrapErr("_loadJSON", err)
			}

			res, err := ExprLoadJSON(file.CacheKey)
			return res, wrapErr("_loadJSON", err)
		},
		new(func(fileSelector string) (any, error)),
		new(func(fileSelector string, env ExprEnv) (any, error)),
	),

	expr.Function(
		"_merge",
		func(params ...any) (any, error) {
			t0 := time.Now()
			defer func() {
				logger.Tracef("[expr] _merge(...) took %s", time.Since(t0))
			}()

			return ExprMerge(params[0].(map[string]any), params[1].(map[string]any)), nil
		},
		new(func(o1, o2 map[string]any) (map[string]any, error)),
	),

	expr.Function(
		"_replaceRegex",
		func(params ...any) (any, error) {
			t0 := time.Now()
			defer func() {
				logger.Tracef("[expr] _replaceRegex(%q, %q, %q) took %s", params[0], params[1], params[2], time.Since(t0))
			}()

			res, err := ExprReplaceRegex(params[0].(string), params[1].(string), params[2].(string))
			return res, wrapErr("_replaceRegex", err)
		},
		new(func(str string, regex string, replacement string) (string, error)),
	),

	expr.Function(
		"_s3Key",
		func(params ...any) (any, error) {
			t0 := time.Now()
			defer func() {
				logger.Tracef("[expr] _merge(...) took %s", time.Since(t0))
			}()

			file, err := fileFromSelector(params[0], params[1])
			if err != nil {
				return "", wrapErr("_s3Key", err)
			}

			return file.S3Path, nil
		},
		new(func(fileSelector string) (string, error)),
		new(func(fileSelector string, env ExprEnv) (string, error)),
	),

	expr.Function(
		"_title",
		func(params ...any) (any, error) {
			t0 := time.Now()
			defer func() {
				logger.Tracef("[expr] _title(%q) took %s", params[0], time.Since(t0))
			}()

			return ExprTitle(params[0].(string)), nil
		},
		new(func(str string) (string, error)),
	),

	expr.Function(
		"_xpath",
		func(params ...any) (any, error) {
			t0 := time.Now()
			defer func() {
				logger.Tracef("[expr] _xpath(%q, ...) took %s", params[0], time.Since(t0))
			}()

			file, err := fileFromSelector(params[0], params[2])
			if err != nil {
				return nil, wrapErr("_xpath", err)
			}

			res, err := ExprXPath(file.CacheKey, params[1].(string))
			return res, wrapErr("_xpath", err)
		},
		new(func(fileSelector string, xpath string) (any, error)),
		new(func(fileSelector string, xpath string, env ExprEnv) (any, error)),
	),
}
View Source
var ExprTestingFunctions = []expr.Option{
	expr.Function(
		"__testCounter__",
		func(params ...any) (any, error) {
			ctx := params[0].(context.Context)

			counter, ok := ctx.Value(ExprTestCounterKey{}).(*atomic.Int64)
			if !ok {
				return nil, errors.New("__testCounter__: context value not found")
			}

			counter.Add(1)

			return nil, nil
		},
		new(func(ctx context.Context) (any, error)),
	),
}

Functions

func ExprCall

func ExprCall(exprName string, env ExprEnv) (any, error)

func ExprExist

func ExprExist(filePath string) (bool, error)

func ExprJQ

func ExprJQ(ctx context.Context, filePath string, jqExpression string) (any, error)

func ExprLoadJSON

func ExprLoadJSON(filePath string) (any, error)

func ExprMerge

func ExprMerge(o1, o2 map[string]any) any

func ExprReplaceRegex

func ExprReplaceRegex(str, regex, replacement string) (string, error)

func ExprTitle

func ExprTitle(value string) string

func ExprXPath

func ExprXPath(filePath string, xpathExpression string) (res any, err error)

Types

type AllImageSummaries

type AllImageSummaries map[string]map[string][]ImageSummary

AllImageSummaries is a map[group] -> map[type] -> images.

type Cache

type Cache interface {
	GetAllImages(ctx context.Context, start, end time.Time) AllImageSummaries
	GetImage(ctx context.Context, bucket, name string) (Image, error)
	GetCachedObject(cacheKey string) ([]byte, error)
	DumpImages() map[string][]string
}

type CachedObject

type CachedObject struct {
	LastModified time.Time `json:"lastModified"`
	CacheKey     string    `json:"cacheKey"`
}

type DynamicInputFile

type DynamicInputFile struct {
	S3Path   string
	CacheKey string
	Date     time.Time
}

type EventType

type EventType string

type ExprEnv

type ExprEnv struct {
	Ctx   context.Context //nolint: containedctx // lives only the duration of the expression evaluation
	Files map[string]DynamicInputFile
	Exprs map[string]*vm.Program
}

type ExprEnvInjector

type ExprEnvInjector struct{}

func (ExprEnvInjector) Visit

func (ExprEnvInjector) Visit(node *ast.Node)

type ExprTestCounterKey

type ExprTestCounterKey struct{}

type Geonames

type Geonames struct {
	CachedObject

	Objects []GeonamesObject `json:"objects"`
}

func (*Geonames) GetTopLevel

func (geonames *Geonames) GetTopLevel() string

func (*Geonames) Sort

func (geonames *Geonames) Sort()

type GeonamesObject

type GeonamesObject struct {
	Name   string `json:"name"`
	States []struct {
		Name     string `json:"name"`
		Counties []struct {
			Name   string `json:"name"`
			Cities []struct {
				Name string `json:"name"`
			} `json:"cities"`
			Villages []struct {
				Name string `json:"name"`
			} `json:"villages"`
		} `json:"counties"`
	} `json:"states"`
}

type Image

type Image struct {
	ImageSummary ImageSummary
	Localization *Localization
	// CachedFileLinks is a map[filename] -> cache key
	CachedFileLinks map[string]string
	// SignedURLs is a map[filename] -> cache key
	SignedURLs map[string]string
	// TargetFiles is a slice of cache keys
	TargetFiles []string
}

type ImageSize

type ImageSize struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

type ImageSummary

type ImageSummary struct {
	Bucket         string              `json:"bucket"`
	Key            string              `json:"key"`
	Name           string              `json:"name"`
	Group          string              `json:"group"`
	Type           string              `json:"type"`
	Geonames       *Geonames           `json:"geonames"`
	ProductInfo    *ProductInformation `json:"productInfo"`
	DynamicFilters map[string]string   `json:"dynamicFilters"`
	// Contains the cache key to the image preview.
	CachedObject CachedObject `json:"cachedObject"`
	Size         ImageSize    `json:"size"`
}

type Localization

type Localization struct {
	CachedObject

	Corner LocalizationCorner `json:"corner" mapstructure:"corner"`
}

type LocalizationCorner

type LocalizationCorner struct {
	UpperLeft  Point `json:"upper-left"`
	UpperRight Point `json:"upper-right"`
	LowerLeft  Point `json:"lower-left"`
	LowerRight Point `json:"lower-right"`
}

type ObjectType

type ObjectType string

type OutEvent

type OutEvent struct {
	EventType   EventType  `json:"eventType"`
	ObjectType  ObjectType `json:"objectType"`
	ImageBucket string     `json:"imageBucket"`
	ImageKey    string     `json:"imageKey"`
	ObjectTime  time.Time  `json:"objectTime"`
	// Only filled for EventCreated
	Object any `json:"object,omitempty"`
	// Eventual error
	Error string `json:"error,omitempty"`
}

func (OutEvent) JSON

func (evt OutEvent) JSON() ([]byte, error)

func (OutEvent) String

func (evt OutEvent) String() string

type Point

type Point struct {
	Coordinates struct {
		Lon float64 `json:"lon"`
		Lat float64 `json:"lat"`
	} `json:"coordinates"`
}

type ProductInformation

type ProductInformation struct {
	Title    string   `json:"title"`
	Subtitle string   `json:"subtitle"`
	Entries  []string `json:"entries"`
	Summary  string   `json:"summary"`
}

Jump to

Keyboard shortcuts

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