Documentation
¶
Index ¶
- Constants
- Variables
- func ExprCall(exprName string, env ExprEnv) (any, error)
- func ExprExist(filePath string) (bool, error)
- func ExprJQ(ctx context.Context, filePath string, jqExpression string) (any, error)
- func ExprLoadJSON(filePath string) (any, error)
- func ExprMerge(o1, o2 map[string]any) any
- func ExprReplaceRegex(str, regex, replacement string) (string, error)
- func ExprTitle(value string) string
- func ExprXPath(filePath string, xpathExpression string) (res any, err error)
- type AllImageSummaries
- type Cache
- type CachedObject
- type DynamicInputFile
- type EventType
- type ExprEnv
- type ExprEnvInjector
- type ExprTestCounterKey
- type Geonames
- type GeonamesObject
- type Image
- type ImageSize
- type ImageSummary
- type Localization
- type LocalizationCorner
- type ObjectType
- type OutEvent
- type Point
- type ProductInformation
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 ExprLoadJSON ¶
func ExprReplaceRegex ¶
Types ¶
type AllImageSummaries ¶
type AllImageSummaries map[string]map[string][]ImageSummary
AllImageSummaries is a map[group] -> map[type] -> images.
type CachedObject ¶
type DynamicInputFile ¶
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 ¶
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 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 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"`
}
Click to show internal directories.
Click to hide internal directories.