mirror of
https://github.com/foomo/contentfulvalidation.git
synced 2025-10-16 12:25:37 +00:00
remove private dependency
This commit is contained in:
parent
9993844e14
commit
67771336f8
8
go.mod
8
go.mod
@ -3,20 +3,16 @@ module github.com/foomo/contentfulvalidation
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/bestbytes/catalogue v0.39.1
|
||||
github.com/foomo/contentful v0.4.4
|
||||
github.com/foomo/contentserver v1.10.2
|
||||
github.com/foomo/gotsrpc/v2 v2.7.2
|
||||
github.com/foomo/keel v0.16.1
|
||||
github.com/go-co-op/gocron v1.33.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
go.uber.org/zap v1.25.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/RoaringBitmap/roaring v1.3.0 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bits-and-blooms/bitset v1.8.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/uuid v1.3.1 // indirect
|
||||
@ -26,16 +22,14 @@ require (
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/mschoch/smat v0.2.0 // indirect
|
||||
github.com/prometheus/client_golang v1.16.0 // indirect
|
||||
github.com/prometheus/client_model v0.3.0 // indirect
|
||||
github.com/prometheus/common v0.42.0 // indirect
|
||||
github.com/prometheus/procfs v0.10.1 // indirect
|
||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||
github.com/rogpeppe/go-internal v1.8.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
go.opentelemetry.io/otel v1.7.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.7.0 // indirect
|
||||
go.uber.org/atomic v1.11.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
golang.org/x/mod v0.11.0 // indirect
|
||||
golang.org/x/sys v0.11.0 // indirect
|
||||
|
||||
27
go.sum
27
go.sum
@ -1,16 +1,8 @@
|
||||
github.com/RoaringBitmap/roaring v1.3.0 h1:aQmu9zQxDU0uhwR8SXOH/OrqEf+X8A0LQmwW3JX8Lcg=
|
||||
github.com/RoaringBitmap/roaring v1.3.0/go.mod h1:plvDsJQpxOC5bw8LRteu/MLWHsHez/3y6cubLI4/1yE=
|
||||
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/bestbytes/catalogue v0.39.1 h1:NAbES4bl8hg5a9UAGpTrrLTV/7PE86HEsGd7O5m/fJg=
|
||||
github.com/bestbytes/catalogue v0.39.1/go.mod h1:eyZEeaZJSqc/r78jejYM+h8fkLnS1Kzd+IPzG0hxLH0=
|
||||
github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
|
||||
github.com/bits-and-blooms/bitset v1.8.0 h1:FD+XqgOZDUxxZ8hzoBFuV9+cGWY9CslN6d5MS5JVb4c=
|
||||
github.com/bits-and-blooms/bitset v1.8.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
|
||||
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@ -22,8 +14,6 @@ github.com/foomo/gotsrpc/v2 v2.7.2 h1:a94V/a8LSssq+aRN3Fv1lJPjWoyMilOvRq+yEaDTHV
|
||||
github.com/foomo/gotsrpc/v2 v2.7.2/go.mod h1:n5SiKVNCZ7Tob6wcROWT5Sx1i/W42+ErpTbNqT3etM8=
|
||||
github.com/foomo/keel v0.16.1 h1:nGPjprqqj96Nuu0LpiNjLSs+a2Cs/ad/px3hGKgE8iA=
|
||||
github.com/foomo/keel v0.16.1/go.mod h1:ExaBRf52e3Z7vzuC+DTbs4i2NYVj49LIvaXFiV6+R84=
|
||||
github.com/go-co-op/gocron v1.33.0 h1:lqQMwewbTIlh2/3l+1ieEjgseZ1AITe6YQQ5bCf0mhY=
|
||||
github.com/go-co-op/gocron v1.33.0/go.mod h1:NLi+bkm4rRSy1F8U7iacZOz0xPseMoIOnvabGoSe/no=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
@ -47,13 +37,10 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm
|
||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
@ -63,8 +50,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM=
|
||||
github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
@ -78,9 +63,6 @@ github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI
|
||||
github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc=
|
||||
github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg=
|
||||
github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
|
||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
|
||||
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
|
||||
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
|
||||
@ -88,13 +70,9 @@ github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYl
|
||||
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
|
||||
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
@ -102,9 +80,6 @@ go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM=
|
||||
go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk=
|
||||
go.opentelemetry.io/otel/trace v1.7.0 h1:O37Iogk1lEkMRXewVtZ1BBTVn5JEp8GrJvP92bJqC6o=
|
||||
go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48yyE4TNvoHqU=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
|
||||
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
|
||||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
@ -130,12 +105,10 @@ google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
moul.io/http2curl v1.0.0 h1:6XwpyZOYsgZJrU8exnG87ncVkU1FVCcTRpwzOkTDUi8=
|
||||
moul.io/http2curl v1.0.0/go.mod h1:f6cULg+e4Md/oW1cYmwW4IWQOVl2lGbmCNGOHvzX2kE=
|
||||
|
||||
@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
catvo "github.com/bestbytes/catalogue/vo"
|
||||
"github.com/foomo/contentful"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@ -43,15 +42,7 @@ func GetAspectRatio(asset *contentful.AssetNoLocale) (float64, error) {
|
||||
return aspectRatio, nil
|
||||
}
|
||||
|
||||
func LoadQuery(rawQuery *interface{}) (*catvo.Query, error) {
|
||||
query := &catvo.Query{}
|
||||
errMarshal := loadInterfaceAsJSON(rawQuery, query)
|
||||
if errMarshal != nil {
|
||||
return nil, errMarshal
|
||||
}
|
||||
return query, nil
|
||||
}
|
||||
func loadInterfaceAsJSON(source interface{}, target interface{}) error {
|
||||
func LoadInterfaceAsJSON(source interface{}, target interface{}) error {
|
||||
jsonBytes, errMarshal := json.Marshal(source)
|
||||
if errMarshal != nil {
|
||||
return errMarshal
|
||||
@ -79,3 +70,19 @@ func IsCorrectImageSize(asset *contentful.AssetNoLocale) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func IsLandscapeRatio(asset *contentful.AssetNoLocale) bool {
|
||||
aspectRatio, err := GetAspectRatio(asset)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return aspectRatio >= 1.00
|
||||
}
|
||||
|
||||
func IsPortraitRatio(asset *contentful.AssetNoLocale) bool {
|
||||
aspectRatio, err := GetAspectRatio(asset)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return aspectRatio <= 1.00
|
||||
}
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
package validations
|
||||
|
||||
import (
|
||||
"github.com/foomo/contentful"
|
||||
"github.com/foomo/contentfulvalidation/utils"
|
||||
)
|
||||
|
||||
func IsLandscapeRatio(asset *contentful.AssetNoLocale) bool {
|
||||
aspectRatio, err := utils.GetAspectRatio(asset)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return aspectRatio >= 1.00
|
||||
}
|
||||
|
||||
func IsPortraitRatio(asset *contentful.AssetNoLocale) bool {
|
||||
aspectRatio, err := utils.GetAspectRatio(asset)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return aspectRatio <= 1.00
|
||||
}
|
||||
@ -1,61 +0,0 @@
|
||||
package validations
|
||||
|
||||
import (
|
||||
catvo "github.com/bestbytes/catalogue/vo"
|
||||
"github.com/foomo/contentfulvalidation/constants"
|
||||
)
|
||||
|
||||
func ValidateQuery(query *catvo.Query, attributes catvo.Attributes) []constants.QueryError {
|
||||
errors := []constants.QueryError{}
|
||||
|
||||
isValueExpired := func(value string, def catvo.AttributeDefinition) {
|
||||
if len(value) < 1 {
|
||||
errors = append(errors, constants.MissingQueryFieldValues)
|
||||
} else {
|
||||
if _, ok := def.EnumStrings[catvo.AttributeValueID(value)]; !ok {
|
||||
errors = append(errors, constants.QueryValueExpired)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
areValuesExpired := func(values []string, def catvo.AttributeDefinition) {
|
||||
if len(values) < 1 {
|
||||
errors = append(errors, constants.MissingQueryFieldValues)
|
||||
}
|
||||
for _, v := range values {
|
||||
isValueExpired(v, def)
|
||||
}
|
||||
}
|
||||
|
||||
for _, e := range query.Elements {
|
||||
if e.Matcher != nil {
|
||||
if def, ok := attributes[e.Matcher.Attribute]; ok {
|
||||
switch {
|
||||
case e.Matcher.StringIn != nil:
|
||||
areValuesExpired(e.Matcher.StringIn.Values, def)
|
||||
case e.Matcher.StringAllIn != nil:
|
||||
areValuesExpired(e.Matcher.StringAllIn.Values, def)
|
||||
case e.Matcher.StringNotIn != nil:
|
||||
areValuesExpired(e.Matcher.StringNotIn.Values, def)
|
||||
case e.Matcher.StringEquals != nil:
|
||||
isValueExpired(e.Matcher.StringEquals.Value, def)
|
||||
case e.Matcher.StringNotEquals != nil:
|
||||
isValueExpired(e.Matcher.StringNotEquals.Value, def)
|
||||
case e.Matcher.IntInRange != nil:
|
||||
case e.Matcher.IntFrom != nil:
|
||||
case e.Matcher.IntTo != nil:
|
||||
case e.Matcher.IntEquals != nil:
|
||||
case e.Matcher.IntNotEquals != nil:
|
||||
case e.Matcher.BoolEquals != nil:
|
||||
case e.Matcher.Bitmap != nil:
|
||||
default:
|
||||
errors = append(errors, constants.MissingQueryCondition)
|
||||
}
|
||||
} else {
|
||||
errors = append(errors, constants.MissingQueryField)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errors
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/bestbytes/catalogue/vo"
|
||||
"github.com/foomo/keel/log"
|
||||
"github.com/go-co-op/gocron"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type AttributeProviderFunc func() vo.Attributes
|
||||
type AttributeUpdateFunc func(ctx context.Context) vo.Attributes
|
||||
|
||||
type AttributeProvider struct {
|
||||
l *zap.Logger
|
||||
ctx context.Context
|
||||
attributes vo.Attributes
|
||||
updateFunc AttributeUpdateFunc
|
||||
}
|
||||
|
||||
func NewAttributeProvider(ctx context.Context, l *zap.Logger, uf AttributeUpdateFunc) *AttributeProvider {
|
||||
return &AttributeProvider{
|
||||
l: l,
|
||||
ctx: ctx,
|
||||
updateFunc: uf,
|
||||
}
|
||||
}
|
||||
|
||||
func (ap *AttributeProvider) Init() error {
|
||||
ap.attributes = ap.updateFunc(ap.ctx)
|
||||
|
||||
// TODO: make configurable
|
||||
s := gocron.NewScheduler(time.Local)
|
||||
_, err := s.Every(1).Day().At("03:00").Do(func() {
|
||||
ap.attributes = ap.updateFunc(ap.ctx)
|
||||
})
|
||||
if err != nil {
|
||||
log.Must(ap.l, err, "failed to initialize attribute provider scheduler")
|
||||
}
|
||||
s.StartAsync()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ap *AttributeProvider) GetAttributes() vo.Attributes {
|
||||
return ap.attributes
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user