diff --git a/.gitea/workflows/build-push.yml b/.gitea/workflows/build-push.yml index 3d2a87a..4d9ec45 100644 --- a/.gitea/workflows/build-push.yml +++ b/.gitea/workflows/build-push.yml @@ -15,4 +15,10 @@ jobs: version: v0.15.4 env: KO_DOCKER_REPO: 192.168.31.55:5000/kedaya/spider - - run: ko build --bare ./cmd \ No newline at end of file + HTTP_PROXY: http://192.168.31.55:10809 + HTTPS_PROXY: http://192.168.31.55:10809 + - run: ko build --bare ./cmd + env: + KO_DOCKER_REPO: 192.168.31.55:5000/kedaya/spider + HTTP_PROXY: http://192.168.31.55:10809 + HTTPS_PROXY: http://192.168.31.55:10809 \ No newline at end of file diff --git a/cmd/main.go b/cmd/main.go index 2304c39..8cb5c1f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -47,7 +47,7 @@ func main() { go pool.CronUpdate(ctx, cfg.Proxy.Interval) //定时更新代理 // coach client - client := coach_client.NewClient(pool) + client := coach_client.USClient(pool) productCtl := product.NewController(client, db) diff --git a/go.mod b/go.mod index 1e2da1b..8f70453 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,12 @@ -module gitea.timerzz.com/kedaya_haitao/coach-spider +module gitea.timerzz.com/kedaya_haitao/coach-cnCoachOutletSpider go 1.22.2 toolchain go1.22.3 require ( - gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240528135655-53c6ee15ffdf + gitea.timerzz.com/kedaya_haitao/coach-spider v0.0.0-20240528135945-420b979a9aa1 + gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240615114454-585b23cbfb48 github.com/gofiber/fiber/v3 v3.0.0-beta.2 github.com/golang/glog v1.2.1 github.com/samber/lo v1.39.0 @@ -26,17 +27,23 @@ require ( github.com/antchfx/xpath v1.3.0 // indirect github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/buger/jsonparser v1.1.1 // indirect + github.com/bytedance/go-tagexpr/v2 v2.9.2 // indirect + github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7 // indirect github.com/bytedance/sonic v1.11.6 // indirect github.com/bytedance/sonic/loader v0.1.1 // indirect github.com/cloudflare/circl v1.3.6 // indirect github.com/cloudwego/base64x v0.1.4 // indirect + github.com/cloudwego/hertz v0.9.1 // indirect github.com/cloudwego/iasm v0.2.0 // indirect + github.com/cloudwego/netpoll v0.6.0 // indirect github.com/coreos/go-iptables v0.7.0 // indirect github.com/corpix/uarand v0.2.0 // indirect github.com/ericlagergren/aegis v0.0.0-20230312195928-b4ce538b56f9 // indirect github.com/ericlagergren/polyval v0.0.0-20220411101811-e25bc10ba391 // indirect github.com/ericlagergren/siv v0.0.0-20220507050439-0b757b3aa5f1 // indirect github.com/ericlagergren/subtle v0.0.0-20220507045147-890d697da010 // indirect + github.com/expr-lang/expr v1.16.9 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/gaukas/godicttls v0.0.4 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-resty/resty/v2 v2.13.1 // indirect @@ -55,6 +62,8 @@ require ( github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 // indirect github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/yamux v0.1.1 // indirect + github.com/henrylee2cn/ameda v1.4.10 // indirect + github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8 // indirect github.com/insomniacslk/dhcp v0.0.0-20240419123447-f1cffa2c0c49 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect @@ -88,7 +97,7 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/mroth/weightedrand/v2 v2.1.0 // indirect - github.com/nxadm/tail v1.4.11 // indirect + github.com/nyaruka/phonenumbers v1.0.55 // indirect github.com/oasisprotocol/deoxysii v0.0.0-20220228165953-2091330c22b7 // indirect github.com/onsi/ginkgo/v2 v2.9.5 // indirect github.com/openacid/low v0.1.21 // indirect @@ -115,6 +124,9 @@ require ( github.com/sina-ghaderi/rabbitio v0.0.0-20220730151941-9ce26f4f872e // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/temoto/robotstxt v1.1.2 // indirect + github.com/tidwall/gjson v1.14.4 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.0 // indirect github.com/timerzz/proxypool v0.0.0-20240512142241-f74bcb3534c5 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect diff --git a/go.sum b/go.sum index da60f9a..c5a0f39 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240528135655-53c6ee15ffdf h1:ev3GfJTfqO2AZmaCiymJYonEGqqpLyiXzX0NRX5ZpPc= -gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240528135655-53c6ee15ffdf/go.mod h1:cgLy4gB0z2UZD3kBp1IAemt28dkaKNdt4RC0LNkE1I8= +gitea.timerzz.com/kedaya_haitao/coach-spider v0.0.0-20240528135945-420b979a9aa1 h1:SuXJiwlstk2vK9zpEoeZRTCmHlck/xRShjrOVNrAlgs= +gitea.timerzz.com/kedaya_haitao/coach-spider v0.0.0-20240528135945-420b979a9aa1/go.mod h1:aBP1HqaXakhww4/AO4Pj3gHi6qpcmHHpD4cY4gkZCZ0= +gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240615114454-585b23cbfb48 h1:qLNGvVh0xja21+ojrhkpz4bWWaWwTEaSWiL1CzMgaaI= +gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240615114454-585b23cbfb48/go.mod h1:uV586p6Z8LIq3I8O/pXZv+jIkIwnwBjAz0D7KrhB9JM= github.com/3andne/restls-client-go v0.1.6 h1:tRx/YilqW7iHpgmEL4E1D8dAsuB0tFF3uvncS+B6I08= github.com/3andne/restls-client-go v0.1.6/go.mod h1:iEdTZNt9kzPIxjIGSMScUFSBrUH6bFRNg0BWlP4orEY= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -37,18 +39,32 @@ github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xW github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= +github.com/bytedance/go-tagexpr/v2 v2.9.2 h1:QySJaAIQgOEDQBLS3x9BxOWrnhqu5sQ+f6HaZIxD39I= +github.com/bytedance/go-tagexpr/v2 v2.9.2/go.mod h1:5qsx05dYOiUXOUgnQ7w3Oz8BYs2qtM/bJokdLb79wRM= +github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7 h1:PtwsQyQJGxf8iaPptPNaduEIu9BnrNms+pcRdHAxZaM= +github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7/go.mod h1:2ZlV9BaUH4+NXIBF0aMdKKAnHTzqH+iMU4KUjAbL23Q= +github.com/bytedance/mockey v1.2.1 h1:g84ngI88hz1DR4wZTL3yOuqlEcq67MretBfQUdXwrmw= +github.com/bytedance/mockey v1.2.1/go.mod h1:+Jm/fzWZAuhEDrPXVjDf/jLM2BlLXJkwk94zf2JZ3X4= +github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= +github.com/bytedance/sonic v1.8.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/circl v1.3.6 h1:/xbKIqSHbZXHwkhbrhrt2YOHIwYJlXH94E3tI/gDlUg= github.com/cloudflare/circl v1.3.6/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/hertz v0.9.1 h1:+jK9A6MDNTUVy6q/zSOlhbnp1fFMiOaPIsq0jlOfjZE= +github.com/cloudwego/hertz v0.9.1/go.mod h1:cs8dH6unM4oaJ5k9m6pqbgLBPqakGWMG0+cthsxitsg= github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= +github.com/cloudwego/netpoll v0.6.0 h1:JRMkrA1o8k/4quxzg6Q1XM+zIhwZsyoWlq6ef+ht31U= +github.com/cloudwego/netpoll v0.6.0/go.mod h1:xVefXptcyheopwNDZjDPcfU6kIjZXZ4nY550k1yH9eQ= github.com/coreos/go-iptables v0.7.0 h1:XWM3V+MPRr5/q51NuWSgU0fqMad64Zyxs8ZUoMsamr8= github.com/coreos/go-iptables v0.7.0/go.mod h1:Qe8Bv2Xik5FyTXwgIbLAnv2sWSBmvWdFETJConOQ//Q= github.com/corpix/uarand v0.2.0 h1:U98xXwud/AVuCpkpgfPF7J5TQgr7R5tqT8VZP5KWbzE= @@ -68,7 +84,9 @@ github.com/ericlagergren/siv v0.0.0-20220507050439-0b757b3aa5f1 h1:tlDMEdcPRQKBE github.com/ericlagergren/siv v0.0.0-20220507050439-0b757b3aa5f1/go.mod h1:4RfsapbGx2j/vU5xC/5/9qB3kn9Awp1YDiEnN43QrJ4= github.com/ericlagergren/subtle v0.0.0-20220507045147-890d697da010 h1:fuGucgPk5dN6wzfnxl3D0D3rVLw4v2SbBT9jb4VnxzA= github.com/ericlagergren/subtle v0.0.0-20220507045147-890d697da010/go.mod h1:JtBcj7sBuTTRupn7c2bFspMDIObMJsVK8TeUvpShPok= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/expr-lang/expr v1.16.9 h1:WUAzmR0JNI9JCiF0/ewwHB1gmcGw5wW7nWt8gc6PpCI= +github.com/expr-lang/expr v1.16.9/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4= +github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/gaukas/godicttls v0.0.4 h1:NlRaXb3J6hAnTmWdsEKb9bcSBD6BvcIjdGdeb0zfXbk= @@ -139,8 +157,15 @@ github.com/google/tink/go v1.6.1 h1:t7JHqO8Ath2w2ig5vjwQYJzhGEZymedQc90lQXUBa4I= github.com/google/tink/go v1.6.1/go.mod h1:IGW53kTgag+st5yPhKKwJ6u2l+SSp5/v9XF7spovjlY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= +github.com/henrylee2cn/ameda v1.4.8/go.mod h1:liZulR8DgHxdK+MEwvZIylGnmcjzQ6N6f2PlWe7nEO4= +github.com/henrylee2cn/ameda v1.4.10 h1:JdvI2Ekq7tapdPsuhrc4CaFiqw6QXFvZIULWJgQyCAk= +github.com/henrylee2cn/ameda v1.4.10/go.mod h1:liZulR8DgHxdK+MEwvZIylGnmcjzQ6N6f2PlWe7nEO4= +github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8 h1:yE9ULgp02BhYIrO6sdV/FPe0xQM6fNHkVQW2IAymfM0= +github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8/go.mod h1:Nhe/DM3671a5udlv2AdV2ni/MZzgfv2qrPL5nIi3EGQ= github.com/insomniacslk/dhcp v0.0.0-20240419123447-f1cffa2c0c49 h1:/OuvSMGT9+xnyZ+7MZQ1zdngaCCAdPoSw8B/uurZ7pg= github.com/insomniacslk/dhcp v0.0.0-20240419123447-f1cffa2c0c49/go.mod h1:KclMyHxX06VrVr0DJmeFSUb1ankt7xTfoOA35pCkoic= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= @@ -160,6 +185,8 @@ github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtL github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +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/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8NzpJ3o= github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak= github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI= @@ -220,6 +247,8 @@ github.com/mroth/weightedrand/v2 v2.1.0 h1:o1ascnB1CIVzsqlfArQQjeMy1U0NcIbBO5rfd github.com/mroth/weightedrand/v2 v2.1.0/go.mod h1:f2faGsfOGOwc1p94wzHKKZyTpcJUW7OJ/9U4yfiNAOU= github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY= github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc= +github.com/nyaruka/phonenumbers v1.0.55 h1:bj0nTO88Y68KeUQ/n3Lo2KgK7lM1hF7L9NFuwcCl3yg= +github.com/nyaruka/phonenumbers v1.0.55/go.mod h1:sDaTZ/KPX5f8qyV9qN+hIm+4ZBARJrupC6LuhshJq1U= github.com/oasisprotocol/deoxysii v0.0.0-20220228165953-2091330c22b7 h1:1102pQc2SEPp5+xrS26wEaeb26sZy6k9/ZXlZN+eXE4= github.com/oasisprotocol/deoxysii v0.0.0-20220228165953-2091330c22b7/go.mod h1:UqoUn6cHESlliMhOnKLWr+CBH+e3bazUPvFj1XZwAjs= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= @@ -288,12 +317,18 @@ github.com/sina-ghaderi/rabbitio v0.0.0-20220730151941-9ce26f4f872e h1:ur8uMsPIF github.com/sina-ghaderi/rabbitio v0.0.0-20220730151941-9ce26f4f872e/go.mod h1:+e5fBW3bpPyo+3uLo513gIUblc03egGjMM0+5GKbzK8= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= 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/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 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= @@ -305,6 +340,13 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8 github.com/temoto/robotstxt v1.1.1/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo= github.com/temoto/robotstxt v1.1.2 h1:W2pOjSJ6SWvldyEuiFXNxz3xZ8aiWX5LbfDiOFd7Fxg= github.com/temoto/robotstxt v1.1.2/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo= +github.com/tidwall/gjson v1.9.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM= +github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/timerzz/proxypool v0.0.0-20240512142241-f74bcb3534c5 h1:/UVxZzOD+N5HVX+A+kDUDVE1cJSHbh4PSfL8H+EW5nM= github.com/timerzz/proxypool v0.0.0-20240512142241-f74bcb3534c5/go.mod h1:Ba8aQPgnCdkBJoKGs9Fb6bPR+RHcmXhsSYVAQzREC8k= github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= @@ -339,6 +381,7 @@ go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go4.org/netipx v0.0.0-20231129151722-fdeea329fbba h1:0b9z3AuHCjxk0x/opv64kcgZLBseWJUpBw5I82+2U4M= go4.org/netipx v0.0.0-20231129151722-fdeea329fbba/go.mod h1:PLyyIXexvUFg3Owu6p/WfdlivPbZJsZdgWZlrGope/Y= +golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff/go.mod h1:flIaEI6LNU6xOCD5PaJvn9wGP0agmIOqjrtsKGRguv4= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= @@ -387,6 +430,7 @@ golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAG golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= @@ -403,12 +447,13 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220110181412-a018aaa089fe/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220622161953-175b2fd9d664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -447,6 +492,7 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -480,6 +526,7 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -489,6 +536,7 @@ gopkg.in/sourcemap.v1 v1.0.5 h1:inv58fC9f9J3TK2Y2R1NPntXEn3/wjWHkonhIUODNTI= gopkg.in/sourcemap.v1 v1.0.5/go.mod h1:2RlvNNSMglmRrcvhfuzp4hQHwOtjxlbjX7UPY/GXb78= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 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= diff --git a/product/calculate.go b/product/calculate.go new file mode 100644 index 0000000..e0488fd --- /dev/null +++ b/product/calculate.go @@ -0,0 +1,126 @@ +package product + +import ( + "errors" + productv1 "gitea.timerzz.com/kedaya_haitao/common/model/product" + "github.com/samber/lo" + "gorm.io/gorm" +) + +const ( + USCoachOutletPid = "us-coach-outlet" +) + +var ( + defaultCalculateProcesses = []productv1.CalculateProcess{ + { + Pid: USCoachOutletPid, + Name: "九折", + Process: "originalPrice * 0.9 * exchangeRate + freight", + }, + { + Pid: USCoachOutletPid, + Name: "150 - 20", + Condition: "originalPrice >= 150", + Process: "(originalPrice - 20) * exchangeRate + freight", + }, + { + Pid: USCoachOutletPid, + Name: "100 - 10", + Condition: "originalPrice >= 100", + Process: "(originalPrice - 10) * exchangeRate + freight", + }, + } +) + +func (c *Controller) LoadCalculateProcess() { + c.db.Model(&productv1.CalculateProcess{}).Find(&c.calculates, "pid = ?", USCoachOutletPid) + if len(c.calculates) == 0 { + c.db.Create(&defaultCalculateProcesses) + c.db.Model(&productv1.CalculateProcess{}).Find(&c.calculates, "pid = ?", USCoachOutletPid) + } +} + +func (c *Controller) GetGlobalCalculateProcess() (cs []productv1.CalculateProcess, err error) { + err = c.db.Model(&productv1.CalculateProcess{}).Find(&cs, "pid = ?", USCoachOutletPid).Error + return +} + +// DeleteGlobalCalculateProcess 删除全局的计算规则 +func (c *Controller) DeleteGlobalCalculateProcess(id uint) error { + if _, idx, exist := lo.FindIndexOf(c.calculates, func(item productv1.CalculateProcess) bool { + return item.ID == id + }); exist { + if err := c.db.Model(&productv1.CalculateProcess{}).Delete(&c.calculates[idx], "id = ?", id).Error; err != nil { + return err + } + c.calculates = append(c.calculates[:idx], c.calculates[idx+1:]...) + go c.updateRate(c.Freight) + } + return nil +} + +// SaveGlobalCalculateProcess 更新全局的计算规则 +func (c *Controller) SaveGlobalCalculateProcess(cs []productv1.CalculateProcess) error { + if len(cs) == 0 { + return nil + } + cs = lo.Filter(cs, func(item productv1.CalculateProcess, index int) bool { + return item.Pid == USCoachOutletPid + }) + return c.db.Transaction(func(tx *gorm.DB) error { + if err := c.db.Save(&cs).Error; err != nil { + return err + } + + if err := c.db.Model(&productv1.CalculateProcess{}).Find(&c.calculates, "pid = ?", USCoachOutletPid).Error; err != nil { + return err + } + go c.updateRate(c.Freight) + return nil + }) +} + +// DeleteCalculateProcess 删除计算规则 +func (c *Controller) DeleteCalculateProcess(id uint) error { + return c.db.Transaction(func(tx *gorm.DB) error { + cal := productv1.CalculateProcess{} + if err := tx.Model(&productv1.CalculateProcess{}).Where("id = ?", id).First(&cal).Error; err != nil && !errors.As(err, &gorm.ErrRecordNotFound) { + return err + } else if errors.As(err, &gorm.ErrRecordNotFound) { + return nil + } + + if err := tx.Model(&productv1.CalculateProcess{}).Where("id = ?", cal.ID).Delete(&cal).Error; err != nil { + return err + } + var product productv1.Product + if err := tx.Preload("CalculateProcess").First(&product, "pid = ? AND website = ?", cal.Pid, productv1.WebSite_US_Coach_Outlet).Error; err != nil { + return err + } + product.ExchangeRate = c.ExchangeRate + product.CalCNY(append(product.CalculateProcess, c.calculates...)) + return tx.Model(&product).Where("pid = ? AND website = ?", product.Pid, productv1.WebSite_US_Coach_Outlet).Select("rate", "cal_mark", "cny_price").Updates(&product).Error + }) +} + +// SaveCalculateProcess 更新计算规则 +func (c *Controller) SaveCalculateProcess(cs []productv1.CalculateProcess) error { + if len(cs) == 0 { + return nil + } + + return c.db.Transaction(func(tx *gorm.DB) error { + if err := c.db.Save(&cs).Error; err != nil { + return err + } + + var product productv1.Product + if err := tx.Preload("CalculateProcess").First(&product, "pid = ? AND website = ?", cs[0].Pid, productv1.WebSite_US_Coach_Outlet).Error; err != nil { + return err + } + product.ExchangeRate = c.ExchangeRate + product.CalCNY(append(product.CalculateProcess, c.calculates...)) + return tx.Model(&product).Where("pid = ? AND website = ?", product.Pid, productv1.WebSite_US_Coach_Outlet).Select("rate", "cal_mark", "cny_price").Updates(&product).Error + }) +} diff --git a/product/controller.go b/product/controller.go index 38b6e78..3f01325 100644 --- a/product/controller.go +++ b/product/controller.go @@ -15,24 +15,26 @@ import ( type Controller struct { ctx context.Context - client *coach_client.Client + client *coach_client.US updateTime time.Time // 上次抓取时间 db *gorm.DB + calculates []productv1.CalculateProcess Option } -func NewController(client *coach_client.Client, db *gorm.DB) *Controller { +func NewController(client *coach_client.US, db *gorm.DB) *Controller { ctl := &Controller{ client: client, db: db, } ctl.AutoMigrate() ctl.LoadOption() + ctl.LoadCalculateProcess() return ctl } func (c *Controller) AutoMigrate() { - if err := c.db.AutoMigrate(&productv1.Product{}, &productv1.HistoryPrice{}, &Option{}); err != nil { + if err := c.db.AutoMigrate(&productv1.Product{}, &productv1.HistoryPrice{}, &Option{}, &productv1.CalculateProcess{}); err != nil { panic(err) } } @@ -85,27 +87,31 @@ func (c *Controller) saveRespData(list []coach_client.Product) error { price, _ := lo.Find(resp.VariantsOnSale, func(item coach_client.Variant) bool { return item.Id == color.VgId }) - // 获取已经存的运费 + // 获取已经存的运费和得物价格 var savedProduct productv1.Product c.db.Model(&savedProduct).Where("pid = ?", color.VgId).Select("freight", "dw_price").Scan(&savedProduct) if savedProduct.Freight == 0 { savedProduct.Freight = c.Freight } - products = append(products, productv1.Product{ - UpdatedAt: time.Now(), - Name: resp.Name, - Pid: color.VgId, - Color: color.Text, - Link: fmt.Sprintf("%s/%s", "https://www.coachoutlet.com", color.Url), - Image: color.Media.Thumbnail.Src, - Orderable: color.Orderable, - DiscPercent: price.Price.MarkdownDiscPercent, - USPrice: price.Price.Sales.Value, - Freight: savedProduct.Freight, - ExchangeRate: c.ExchangeRate, - DWPrice: savedProduct.DWPrice, - Discount: c.Discount, - }) + p := productv1.Product{ + UpdatedAt: time.Now(), + Name: resp.Name, + Pid: color.VgId, + Color: color.Text, + Link: fmt.Sprintf("%s/%s", "https://www.coachoutlet.com", color.Url), + Image: color.Media.Thumbnail.Src, + Orderable: color.Orderable, + DiscPercent: price.Price.MarkdownDiscPercent, + OriginalPrice: price.Price.Sales.Value, + Freight: savedProduct.Freight, + ExchangeRate: c.ExchangeRate, + DWPrice: savedProduct.DWPrice, + } + + var calculate []productv1.CalculateProcess + c.db.Model(&productv1.CalculateProcess{}).Find(&calculate, "pid = ? AND website = ?", color.VgId, productv1.WebSite_US_Coach_Outlet) + p.CalCNY(append(calculate, c.calculates...)) + products = append(products, p) } } // 去重 diff --git a/product/option.go b/product/option.go index e15d862..49eba24 100644 --- a/product/option.go +++ b/product/option.go @@ -11,11 +11,10 @@ type Option struct { Interval time.Duration `yaml:"interval" json:"interval"` ExchangeRate float64 `yaml:"exchangeRate" json:"exchangeRate"` //汇率 Freight float64 `yaml:"freight" json:"freight"` //运费 - Discount int `yaml:"discount" json:"discount"` //折扣 } func (c *Controller) LoadOption() { - c.db.Where("id = ?", 1).Attrs(Option{Interval: time.Hour * 12, ExchangeRate: 7.3, Freight: 100, Discount: 100}).FirstOrCreate(&c.Option) + c.db.Where("id = ?", 1).Attrs(Option{Interval: time.Hour * 12, ExchangeRate: 7.3, Freight: 100}).FirstOrCreate(&c.Option) } func (c *Controller) SaveOption(opt Option) { @@ -32,14 +31,11 @@ func (c *Controller) SaveOption(opt Option) { c.Option.Freight, oldFreight = opt.Freight, c.Option.Freight change = true } - if opt.Discount > 0 && opt.Discount != c.Option.Discount { - c.Option.Discount = opt.Discount - change = true - } + opt.ID = 1 c.db.Updates(opt) if change { - c.updateRate(oldFreight) + go c.updateRate(oldFreight) } } @@ -51,7 +47,9 @@ func (c *Controller) updateRate(oldFreight float64) { result.Freight = c.Option.Freight } result.ExchangeRate = c.Option.ExchangeRate - result.Discount = c.Option.Discount + var calculate []productv1.CalculateProcess + c.db.Find(&calculate, "pid = ? AND website = ?", result.Pid, productv1.WebSite_US_Coach_Outlet) + result.CalCNY(append(calculate, c.calculates...)) } // 保存对当前批记录的修改 diff --git a/server/spider.go b/server/spider.go index 955615e..7ef3638 100644 --- a/server/spider.go +++ b/server/spider.go @@ -2,7 +2,9 @@ package server import ( "gitea.timerzz.com/kedaya_haitao/coach-spider/product" + productv1 "gitea.timerzz.com/kedaya_haitao/common/model/product" "github.com/gofiber/fiber/v3" + "strconv" ) type SpiderSvc struct { @@ -16,8 +18,13 @@ func NewSpiderSvc(ctl *product.Controller) *SpiderSvc { } func (s *SpiderSvc) RegistryRouter(r fiber.Router) { - r.Get("spider/cfg", s.GetSpiderCfg) - r.Post("spider/cfg", s.SetSpiderCfg) + r.Get("spider/us/coach-outlet/cfg", s.GetSpiderCfg) + r.Post("spider/us/coach-outlet/cfg", s.SetSpiderCfg) + r.Get("spider/us/coach-outlet/global/calculate", s.GetGlobalCalculate) + r.Post("spider/us/coach-outlet/global/calculate", s.UpsertGlobalCalculate) + r.Delete("spider/us/coach-outlet/global/calculate/u/:id", s.DelGlobalCalculate) + r.Post("spider/us/coach-outlet/calculate", s.UpsertCalculate) + r.Delete("spider/us/coach-outlet/calculate/u/:id", s.DelCalculate) } func (s *SpiderSvc) GetSpiderCfg(ctx fiber.Ctx) error { @@ -33,3 +40,57 @@ func (s *SpiderSvc) SetSpiderCfg(ctx fiber.Ctx) error { s.ctl.SaveOption(opt) return nil } + +func (s *SpiderSvc) GetGlobalCalculate(ctx fiber.Ctx) error { + cals, err := s.ctl.GetGlobalCalculateProcess() + if err != nil { + return err + } + return ctx.JSON(cals) +} + +func (s *SpiderSvc) DelGlobalCalculate(ctx fiber.Ctx) error { + idStr := ctx.Params("id") + if idStr == "" { + return fiber.ErrBadRequest + } + id, _ := strconv.Atoi(idStr) + if err := s.ctl.DeleteGlobalCalculateProcess(uint(id)); err != nil { + return err + } + return nil +} + +func (s *SpiderSvc) UpsertGlobalCalculate(ctx fiber.Ctx) error { + var cs []productv1.CalculateProcess + if err := ctx.Bind().JSON(&cs); err != nil { + return err + } + if err := s.ctl.SaveGlobalCalculateProcess(cs); err != nil { + return err + } + return nil +} + +func (s *SpiderSvc) DelCalculate(ctx fiber.Ctx) error { + idStr := ctx.Params("id") + if idStr == "" { + return fiber.ErrBadRequest + } + id, _ := strconv.Atoi(idStr) + if err := s.ctl.DeleteCalculateProcess(uint(id)); err != nil { + return err + } + return nil +} + +func (s *SpiderSvc) UpsertCalculate(ctx fiber.Ctx) error { + var cs []productv1.CalculateProcess + if err := ctx.Bind().JSON(&cs); err != nil { + return err + } + if err := s.ctl.SaveCalculateProcess(cs); err != nil { + return err + } + return nil +}