refactor(http): replace gorequest with req/v3 library

This commit is contained in:
liyp 2024-09-08 16:46:05 +08:00
parent 327a83b8ad
commit cb0e2647a9
12 changed files with 224 additions and 237 deletions

21
go.mod
View file

@ -7,13 +7,13 @@ require github.com/BurntSushi/toml v1.3.2
require ( require (
github.com/goccy/go-json v0.10.2 github.com/goccy/go-json v0.10.2
github.com/mattn/go-sqlite3 v1.14.22 github.com/mattn/go-sqlite3 v1.14.22
github.com/parnurzeal/gorequest v0.3.0
) )
require ( require (
github.com/andybalholm/cascadia v1.3.2 // indirect github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/bytedance/sonic v1.11.6 // indirect github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect github.com/cloudwego/iasm v0.2.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gabriel-vasile/mimetype v1.4.3 // indirect
@ -21,19 +21,33 @@ require (
github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/leodido/go-urn v1.4.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/onsi/ginkgo/v2 v2.16.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/quic-go v0.41.0 // indirect
github.com/refraction-networking/utls v1.6.3 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect github.com/ugorji/go/codec v1.2.12 // indirect
go.uber.org/mock v0.4.0 // indirect
golang.org/x/arch v0.8.0 // indirect golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.24.0 // indirect golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/sys v0.21.0 // indirect golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/protobuf v1.34.1 // indirect google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
) )
@ -41,12 +55,9 @@ require (
require ( require (
github.com/PuerkitoBio/goquery v1.9.2 github.com/PuerkitoBio/goquery v1.9.2
github.com/andybalholm/brotli v1.1.0 github.com/andybalholm/brotli v1.1.0
github.com/elazarl/goproxy v0.0.0-20240618083138-03be62527ccb // indirect
github.com/gin-gonic/gin v1.10.0 github.com/gin-gonic/gin v1.10.0
github.com/moul/http2curl v1.0.0 // indirect github.com/imroc/req/v3 v3.44.0
github.com/pkg/errors v0.9.1 // indirect
github.com/sashabaranov/go-openai v1.29.0 github.com/sashabaranov/go-openai v1.29.0
github.com/sirupsen/logrus v1.9.3 github.com/sirupsen/logrus v1.9.3
github.com/smartystreets/goconvey v1.8.1 // indirect
golang.org/x/net v0.26.0 // indirect golang.org/x/net v0.26.0 // indirect
) )

75
go.sum
View file

@ -10,22 +10,24 @@ github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= 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 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= 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/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= 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/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
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.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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/elazarl/goproxy v0.0.0-20240618083138-03be62527ccb h1:2SoxRauy2IqekRMggrQk3yNI5X6omSnk6ugVbFywwXs=
github.com/elazarl/goproxy v0.0.0-20240618083138-03be62527ccb/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
@ -34,21 +36,36 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g= github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7 h1:y3N7Bm7Y9/CtpiVkw/ZWj6lSlDF3F74SfKwfTCer72Q=
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k= github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/imroc/req/v3 v3.44.0 h1:JBrxoN5DykYvkeEZx3dski8/A+WVz9HD147cwEeyFlM=
github.com/imroc/req/v3 v3.44.0/go.mod h1:6cQ91w7qPn+bYjcWnA1S/LmTh6z3cz8Oa9qdwm7gS8w=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= 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/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
@ -60,30 +77,33 @@ 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/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 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs= github.com/onsi/ginkgo/v2 v2.16.0 h1:7q1w9frJDzninhXxjZd+Y/x54XNjG/UlRLIYPZafsPM=
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= github.com/onsi/ginkgo/v2 v2.16.0/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs=
github.com/parnurzeal/gorequest v0.3.0 h1:SoFyqCDC9COr1xuS6VA8fC8RU7XyrJZN2ona1kEX7FI= github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8=
github.com/parnurzeal/gorequest v0.3.0/go.mod h1:3Kh2QUMJoqw3icWAecsyzkpY7UzRfDhbRdTjtNwNiUE= github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc= github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
github.com/quic-go/quic-go v0.41.0 h1:aD8MmHfgqTURWNJy48IYFg2OnxwHT3JL7ahGs73lb4k=
github.com/quic-go/quic-go v0.41.0/go.mod h1:qCkNjqczPEvgsOnxZ0eCD14lv+B2LHlFAB++CNOh9hA=
github.com/refraction-networking/utls v1.6.3 h1:MFOfRN35sSx6K5AZNIoESsBuBxS2LCgRilRIdHb6fDc=
github.com/refraction-networking/utls v1.6.3/go.mod h1:yil9+7qSl+gBwJqztoQseO6Pr3h62pQoY1lXiNR/FPs=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/sashabaranov/go-openai v1.29.0 h1:eBH6LSjtX4md5ImDCX8hNhHQvaRf22zujiERoQpsvLo= github.com/sashabaranov/go-openai v1.29.0 h1:eBH6LSjtX4md5ImDCX8hNhHQvaRf22zujiERoQpsvLo=
github.com/sashabaranov/go-openai v1.29.0/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg= github.com/sashabaranov/go-openai v1.29.0/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY=
github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec=
github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY=
github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 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.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.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= 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.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
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.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.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.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
@ -96,6 +116,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
@ -103,8 +125,12 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
@ -115,6 +141,8 @@ golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/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-20220722155255-886fb9371eb4/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.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/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-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@ -141,13 +169,14 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 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 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View file

@ -8,7 +8,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/parnurzeal/gorequest" "github.com/imroc/req/v3"
) )
func main() { func main() {
@ -60,8 +60,10 @@ func main() {
// log.Fatal(err) // log.Fatal(err)
// } // }
url := "http://" + cfg["APIURL"].(string) url := "http://" + cfg["APIURL"].(string)
request := gorequest.New() client := req.C()
_, _, err := request.Post(url).Send(message).End() _, err := client.R().
SetBodyJsonMarshal(message).
Post(url)
if err != nil { if err != nil {
fmt.Println("Error:", err) fmt.Println("Error:", err)
} }

View file

@ -180,11 +180,15 @@ func (a *AI) GetMsg() string {
func stripMarkdown(text string) string { func stripMarkdown(text string) string {
println("before:", text) // println("before:", text)
// 移除代码块,但保留代码内容 // 移除代码块,但保留代码内容
re := regexp.MustCompile("(?s)```.*?```") re := regexp.MustCompile("(?s)```(?:\\w+\\s*\n)?(.*?)```")
text = re.ReplaceAllStringFunc(text, func(match string) string { text = re.ReplaceAllStringFunc(text, func(match string) string {
return strings.TrimPrefix(strings.TrimSuffix(match, "```"), "```") submatches := re.FindStringSubmatch(match)
if len(submatches) > 1 {
return strings.TrimSpace(submatches[1])
}
return match
}) })
// 移除行内代码 // 移除行内代码
@ -226,7 +230,7 @@ func stripMarkdown(text string) string {
// 移除多余的空行 // 移除多余的空行
re = regexp.MustCompile(`\n{3,}`) re = regexp.MustCompile(`\n{3,}`)
text = re.ReplaceAllString(text, "\n\n") text = re.ReplaceAllString(text, "\n\n")
println("after:", text) // println("after:", text)
return strings.TrimSpace(text) return strings.TrimSpace(text)
} }

View file

@ -1,11 +1,10 @@
package workers package workers
import ( import (
"encoding/json"
"fmt" "fmt"
"go-bot/config" "go-bot/config"
"github.com/parnurzeal/gorequest" "github.com/imroc/req/v3"
) )
type Worker interface { type Worker interface {
@ -123,20 +122,18 @@ func (s *StdAns) GetHisMsg(id string) (string, string, string) {
} }
url := cfg["POSTURL"].(string) + "/get_msg?message_id=" + id url := cfg["POSTURL"].(string) + "/get_msg?message_id=" + id
request := gorequest.New() var data map[string]interface{}
resp, body, errs := request.Post(url).End() cli := req.C()
if len(errs) > 0 { resp, err := cli.R().
SetSuccessResult(&data).
fmt.Println("Error sending request:", errs) Get(url)
return "", "", ""
}
defer resp.Body.Close()
data := make(map[string]interface{})
err := json.Unmarshal([]byte(body), &data)
if err != nil { if err != nil {
fmt.Println("解析JSON失败:", err) fmt.Println("Error sending request:", err)
return "", "", "" return "", "", ""
} }
defer resp.Body.Close()
if data["status"] == "ok" { if data["status"] == "ok" {
message := data["data"].(map[string]interface{})["message"].([]interface{})[0].(map[string]interface{})["data"].(map[string]interface{}) message := data["data"].(map[string]interface{})["message"].([]interface{})[0].(map[string]interface{})["data"].(map[string]interface{})
@ -153,34 +150,24 @@ func (s *StdAns) SendMsg(msg string) bool {
if msg == "-1" { if msg == "-1" {
return false return false
} }
requestBody, err := json.Marshal(map[string]interface{}{
// "action": "send_msg",
// "params": map[string]interface{}{
"group_id": s.GID,
"message": msg,
// },
})
if err != nil {
fmt.Println("Error marshaling JSON:", err)
return false
}
_, err = json.MarshalIndent(requestBody, "", " ")
if err != nil {
fmt.Println("Error marshaling JSON:", err)
return false
}
// fmt.Println(string(re))
url := cfg["POSTURL"].(string) + "/send_msg" url := cfg["POSTURL"].(string) + "/send_msg"
// println("core:", url) // println("core:", url)
// fmt.Println("请求地址:", url) // fmt.Println("请求地址:", url)
// fmt.Println("响应信息:\n", msg) // fmt.Println("响应信息:\n", msg)
request := gorequest.New() client := req.C()
resp, _, errs := request.Post(url).
Set("Content-Type", "application/json").
Send(string(requestBody)).End()
if len(errs) > 0 {
resp, err := client.R().
SetHeader("Content-Type", "application/json").
SetBodyJsonMarshal(map[string]interface{}{
// "action": "send_msg",
// "params": map[string]interface{}{
"group_id": s.GID,
"message": msg,
// },
}).
Post(url)
if err != nil {
fmt.Println("Error sending request:", err) fmt.Println("Error sending request:", err)
return false return false
} }
@ -196,20 +183,18 @@ func (s *StdAns) GetImage(file string) string {
} }
url := cfg["POSTURL"].(string) + "/get_image?file=" + file url := cfg["POSTURL"].(string) + "/get_image?file=" + file
request := gorequest.New() client := req.C()
resp, body, errs := request.Post(url).End() var data map[string]interface{}
if len(errs) > 0 { resp, err := client.R().
SetSuccessResult(&data).
Get(url)
if err != nil {
fmt.Println("Error sending request:", errs) fmt.Println("Error sending request:", err)
return "" return ""
} }
defer resp.Body.Close() defer resp.Body.Close()
data := make(map[string]interface{})
err := json.Unmarshal([]byte(body), &data)
if err != nil {
fmt.Println("解析JSON失败:", err)
return ""
}
// fmt.Println("url:", url) // fmt.Println("url:", url)
path, ok := data["data"].(map[string]interface{})["file"].(string) path, ok := data["data"].(map[string]interface{})["file"].(string)
if !ok { if !ok {

View file

@ -2,11 +2,10 @@ package workers
import ( import (
"fmt" "fmt"
"io"
"net/http"
"strings" "strings"
"time"
"github.com/goccy/go-json" "github.com/imroc/req/v3"
) )
func init() { func init() {
@ -34,23 +33,24 @@ func (a *Hhsh) GetMsg() string {
url := "https://api.beiyu.vip/api/hhsh?str=" + parms[1] url := "https://api.beiyu.vip/api/hhsh?str=" + parms[1]
// 输出请求地址 // 输出请求地址
// fmt.Println("url:", url) // fmt.Println("url:", url)
req, err := http.Get(url)
var data map[string]interface{}
client := req.C().SetTimeout(time.Second * 10)
resp, err := client.R().
SetSuccessResult(&data).
Get(url)
if err != nil { if err != nil {
return "接口异常!" return "接口异常!"
} }
defer req.Body.Close() defer resp.Body.Close()
body, err := io.ReadAll(req.Body)
if err != nil { fmt.Println("hhsh body:", resp.String())
return err.Error()
}
// fmt.Println("pkg body:", string(body))
// var pkg []Package // var pkg []Package
var data map[string]interface{}
err = json.Unmarshal(body, &data)
if err != nil {
return err.Error()
}
resultSlipe := data["data"].([]interface{}) resultSlipe := data["data"].([]interface{})
fmt.Println("resultSlipe:", resultSlipe) fmt.Println("resultSlipe:", resultSlipe)
if trans, ok := resultSlipe[0].(map[string]interface{})["trans"]; ok { if trans, ok := resultSlipe[0].(map[string]interface{})["trans"]; ok {

View file

@ -4,12 +4,12 @@ import (
"compress/gzip" "compress/gzip"
"fmt" "fmt"
"io" "io"
"log" "time"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"github.com/andybalholm/brotli" "github.com/andybalholm/brotli"
"github.com/parnurzeal/gorequest" "github.com/imroc/req/v3"
) )
func init() { func init() {
@ -30,11 +30,11 @@ func (a *HttpCat) GetMsg() string {
} }
baseUrl := "https://http.cat/" baseUrl := "https://http.cat/"
picUrl := baseUrl + "images/" + a.Parms[1] + ".jpg" picUrl := baseUrl + "images/" + a.Parms[1] + ".jpg"
// 使用 gorequest 发起 HEAD 请求检查资源是否存在 // 使用 req 发起 HEAD 请求检查资源是否存在
request := gorequest.New() client := req.C().SetTimeout(5 * time.Second)
resp, _, errs := request.Head(picUrl).End() resp, err := client.R().Head(picUrl)
if len(errs) > 0 { if err != nil {
return "请求错误: " + fmt.Sprint(errs) return "请求错误: " + err.Error()
} }
// 判断资源是否存在 // 判断资源是否存在
@ -43,34 +43,34 @@ func (a *HttpCat) GetMsg() string {
} }
respContent := "[CQ:image,file=" + picUrl + "]" respContent := "[CQ:image,file=" + picUrl + "]"
docUrl := "https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status/" + a.Parms[1] docUrl := "https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status/" + a.Parms[1]
res, _, errs := request.Get(docUrl). resp, err = client.R().
Set("Host", "developer.mozilla.org"). SetHeader("Host", "developer.mozilla.org").
Set("User-Agent", "Apifox/1.0.0 (https://apifox.com)"). SetHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)").
Set("Accept", "*/*"). SetHeader("Accept", "*/*").
Set("Content-Type", "text/plain"). SetHeader("Content-Type", "text/plain").
End() Get(docUrl)
if len(errs) > 0 { if err != nil {
log.Println("请求错误: " + fmt.Sprint(errs)) return "请求错误: " + err.Error()
} }
if res != nil { if resp != nil {
defer res.Body.Close() defer resp.Body.Close()
} }
if res != nil && res.StatusCode == 200 { if resp != nil && resp.StatusCode == 200 {
// 解压缩响应体 // 解压缩响应体
var reader io.ReadCloser var reader io.ReadCloser
switch res.Header.Get("Content-Encoding") { switch resp.Header.Get("Content-Encoding") {
case "br": case "br":
reader = io.NopCloser(brotli.NewReader(res.Body)) reader = io.NopCloser(brotli.NewReader(resp.Body))
case "gzip": case "gzip":
var err error var err error
reader, err = gzip.NewReader(res.Body) reader, err = gzip.NewReader(resp.Body)
if err != nil { if err != nil {
fmt.Println("gzip 解压错误:", err) fmt.Println("gzip 解压错误:", err)
return respContent return respContent
} }
defer reader.Close() defer reader.Close()
default: default:
reader = res.Body reader = resp.Body
} }
// 使用 goquery 解析 HTML // 使用 goquery 解析 HTML

View file

@ -4,12 +4,12 @@ import (
"compress/gzip" "compress/gzip"
"fmt" "fmt"
"io" "io"
"log" "time"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"github.com/andybalholm/brotli" "github.com/andybalholm/brotli"
"github.com/parnurzeal/gorequest" "github.com/imroc/req/v3"
) )
func init() { func init() {
@ -30,11 +30,11 @@ func (a *HttpDog) GetMsg() string {
} }
baseUrl := "https://http.dog/" baseUrl := "https://http.dog/"
picUrl := baseUrl + a.Parms[1] + ".jpg" picUrl := baseUrl + a.Parms[1] + ".jpg"
// 使用 gorequest 发起 HEAD 请求检查资源是否存在 // 使用 req 发起 HEAD 请求检查资源是否存在
request := gorequest.New() client := req.C().SetTimeout(time.Second * 5)
resp, _, errs := request.Head(picUrl).End() resp, err := client.R().Head(picUrl)
if len(errs) > 0 { if err != nil {
return "请求错误: " + fmt.Sprint(errs) return "请求错误: " + err.Error()
} }
// 判断资源是否存在 // 判断资源是否存在
@ -43,34 +43,34 @@ func (a *HttpDog) GetMsg() string {
} }
respContent := "[CQ:image,file=" + picUrl + "]" respContent := "[CQ:image,file=" + picUrl + "]"
docUrl := "https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status/" + a.Parms[1] docUrl := "https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status/" + a.Parms[1]
res, _, errs := request.Get(docUrl). resp, err = client.R().
Set("Host", "developer.mozilla.org"). SetHeader("Host", "developer.mozilla.org").
Set("User-Agent", "Apifox/1.0.0 (https://apifox.com)"). SetHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)").
Set("Accept", "*/*"). SetHeader("Accept", "*/*").
Set("Content-Type", "text/plain"). SetHeader("Content-Type", "text/plain").
End() Get(docUrl)
if len(errs) > 0 { if err != nil {
log.Println("请求错误: " + fmt.Sprint(errs)) return "请求错误: " + err.Error()
} }
if res != nil { if resp != nil {
defer res.Body.Close() defer resp.Body.Close()
} }
if res != nil && res.StatusCode == 200 { if resp != nil && resp.StatusCode == 200 {
// 解压缩响应体 // 解压缩响应体
var reader io.ReadCloser var reader io.ReadCloser
switch res.Header.Get("Content-Encoding") { switch resp.Header.Get("Content-Encoding") {
case "br": case "br":
reader = io.NopCloser(brotli.NewReader(res.Body)) reader = io.NopCloser(brotli.NewReader(resp.Body))
case "gzip": case "gzip":
var err error var err error
reader, err = gzip.NewReader(res.Body) reader, err = gzip.NewReader(resp.Body)
if err != nil { if err != nil {
fmt.Println("gzip 解压错误:", err) fmt.Println("gzip 解压错误:", err)
return respContent return respContent
} }
defer reader.Close() defer reader.Close()
default: default:
reader = res.Body reader = resp.Body
} }
// 使用 goquery 解析 HTML // 使用 goquery 解析 HTML

View file

@ -1,15 +1,12 @@
package workers package workers
import ( import (
"bytes"
"fmt" "fmt"
"io"
"net" "net"
"net/http"
"strings" "strings"
"time" "time"
"github.com/goccy/go-json" "github.com/imroc/req/v3"
) )
func init() { func init() {
@ -30,8 +27,9 @@ func (a *Ip) GetMsg() string {
} }
// 去除换行符 // 去除换行符
raw_msg := strings.TrimRight(a.RawMsg, "\n") raw_msg := strings.TrimRight(a.RawMsg, "\n")
fmt.Println("raw_msg:", raw_msg) // fmt.Println("raw_msg:", raw_msg)
parms := strings.Fields(raw_msg) parms := strings.Fields(raw_msg)
client := req.C().SetTimeout(5 * time.Second)
var ip string var ip string
if net.ParseIP(parms[1]) != nil { if net.ParseIP(parms[1]) != nil {
ip = parms[1] ip = parms[1]
@ -40,65 +38,38 @@ func (a *Ip) GetMsg() string {
data := map[string]string{ data := map[string]string{
"url": parms[1], "url": parms[1],
} }
json_data, _ := json.Marshal(data) var resp_data map[string]interface{}
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(json_data)) _, err := client.R().
req.Header.Set("Content-Type", "application/json") SetSuccessResult(&resp_data).
req.Header.Set("x-api-key", "d84eae04-0654-4173-bc6a-c457c4fc3f4d") SetBodyJsonMarshal(data).
SetHeader("Content-Type", "application/json").
client := &http.Client{ SetHeader("x-api-key", "d84eae04-0654-4173-bc6a-c457c4fc3f4d").
Timeout: 5 * time.Second, // 设置超时时间为5秒 Post(url)
}
resp, err := client.Do(req)
if err != nil { if err != nil {
fmt.Println("err:", err) return "DNS解析失败"
return "连接超时!"
} else {
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
println(string(body))
if err != nil {
fmt.Println("err:", err)
} else {
var resp_data map[string]interface{}
err := json.Unmarshal(body, &resp_data)
if err != nil {
return "DNS解析失败"
}
ip = resp_data["data"].(map[string]interface{})["ip"].(string)
// print("ip: ", ip)
}
} }
if resp_data["data"] != nil {
ip = resp_data["data"].(map[string]interface{})["ip"].(string)
// print("ip: ", ip)
}
} }
url := "https://api.ip.sb/geoip/" + ip url := "https://api.ip.sb/geoip/" + ip
fmt.Println("url: ", url) fmt.Println("url: ", url)
var data map[string]interface{}
req, err := http.NewRequest("GET", url, nil) resp, err := client.R().
if err != nil { SetSuccessResult(&data).
fmt.Println("创建请求失败:", err) SetHeader("User-Agent", "Mozilla/5.0").
} Get(url)
req.Header.Set("User-Agent", "Mozilla/5.0")
resp, err := http.DefaultClient.Do(req)
if err != nil { if err != nil {
return "ip查询失败" return "ip查询失败"
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return "ip查询失败"
}
// fmt.Println("body: ", string(body)) // fmt.Println("body: ", string(body))
var data map[string]interface{}
err = json.Unmarshal(body, &data)
if err != nil {
fmt.Println("data: ", data)
return err.Error()
}
// 输出响应数据 // 输出响应数据
fmt.Println("data: ", data) fmt.Println("data: ", data)
if _, ok := data["code"].(float64); ok { if _, ok := data["code"].(float64); ok {

View file

@ -22,7 +22,6 @@ type Lsp struct {
} }
func (a *Lsp) GetMsg() string { func (a *Lsp) GetMsg() string {
a.AllowGroup = append(a.AllowGroup, []string{"313047773"})
url := "https://api.lolicon.app/setu/v2?r18=0&size=small" url := "https://api.lolicon.app/setu/v2?r18=0&size=small"
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {

View file

@ -1,12 +1,12 @@
package workers package workers
import ( import (
"encoding/json"
"fmt" "fmt"
"sort" "sort"
"strconv" "strconv"
"time"
"github.com/parnurzeal/gorequest" "github.com/imroc/req/v3"
) )
func init() { func init() {
@ -26,17 +26,17 @@ func (a *Mner) GetMsg() string {
return "请输入AUR的维护者 如:/mner user 查询 user 用户维护的包" return "请输入AUR的维护者 如:/mner user 查询 user 用户维护的包"
} }
user := a.Parms[1] user := a.Parms[1]
client := req.C().SetTimeout(time.Second * 10)
url := "https://aur.archlinux.org/rpc/v5/search/" + user + "?by=maintainer" url := "https://aur.archlinux.org/rpc/v5/search/" + user + "?by=maintainer"
request := gorequest.New()
_, body, errs := request.Get(url).End()
if len(errs) > 0 {
return "服务器网络错误!"
}
var result map[string]interface{} var result map[string]interface{}
err := json.Unmarshal([]byte(body), &result) resp, err := client.R().
SetSuccessResult(&result).
Get(url)
if err != nil { if err != nil {
return err.Error() return "网络错误!"
} }
defer resp.Body.Close()
results := result["results"].([]interface{}) results := result["results"].([]interface{})
if len(results) == 0 { if len(results) == 0 {
return "未找到该维护者维护的包" return "未找到该维护者维护的包"

View file

@ -5,8 +5,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/goccy/go-json" "github.com/imroc/req/v3"
"github.com/parnurzeal/gorequest"
) )
func init() { func init() {
@ -30,7 +29,7 @@ func (a *Pkg) GetMsg() string {
raw_msg := strings.TrimRight(a.RawMsg, "\n") raw_msg := strings.TrimRight(a.RawMsg, "\n")
raw_msg = strings.TrimRight(raw_msg, "\r") raw_msg = strings.TrimRight(raw_msg, "\r")
fmt.Println("raw_msg:", raw_msg) // fmt.Println("raw_msg:", raw_msg)
parms := strings.Split(raw_msg, " ") parms := strings.Split(raw_msg, " ")
url := "https://archlinux.org/packages/search/json/?name=" + parms[1] url := "https://archlinux.org/packages/search/json/?name=" + parms[1]
@ -39,36 +38,34 @@ func (a *Pkg) GetMsg() string {
} }
// 输出请求地址 // 输出请求地址
// fmt.Println("pkg url:", url) // fmt.Println("pkg url:", url)
request := gorequest.New()
_, body, errs := request.Get(url).End() client := req.C().SetTimeout(time.Second * 10)
if len(errs) > 0 {
var pkg map[string]interface{}
resp, err := client.R().
SetSuccessResult(&pkg).
Get(url)
if err != nil {
return "服务器网络错误!" return "服务器网络错误!"
} }
defer resp.Body.Close()
// fmt.Println("pkg body:", string(body)) // fmt.Println("pkg body:", string(body))
// var pkg []Package // var pkg []Package
var pkg map[string]interface{}
err := json.Unmarshal([]byte(body), &pkg)
if err != nil {
return err.Error()
}
// fmt.Println("pkg:", pkg) // fmt.Println("pkg:", pkg)
resultSlipe := pkg["results"].([]interface{}) resultSlipe := pkg["results"].([]interface{})
if len(resultSlipe) == 0 { if len(resultSlipe) == 0 {
url := "https://aur.archlinux.org/rpc/v5/suggest/" + parms[1] url := "https://aur.archlinux.org/rpc/v5/suggest/" + parms[1]
_, body, errs := request.Get(url).End()
if len(errs) > 0 {
fmt.Println(errs)
}
// fmt.Println("aur suggest url:", url)
// fmt.Println(string(re))
var suggestions []string var suggestions []string
err := json.Unmarshal([]byte(body), &suggestions) resp, err := client.R().
SetSuccessResult(&suggestions).Get(url)
if err != nil { if err != nil {
fmt.Println(err) return "服务器网络错误!"
} }
defer resp.Body.Close()
// println(len(suggestions)) // println(len(suggestions))
if len(suggestions) == 0 { if len(suggestions) == 0 {
return "没有找到相关软件" return "没有找到相关软件"
@ -77,19 +74,12 @@ func (a *Pkg) GetMsg() string {
var searchResult map[string]interface{} var searchResult map[string]interface{}
if len(suggestions) == 1 || suggestions[0] == parms[1] { if len(suggestions) == 1 || suggestions[0] == parms[1] {
searchUrl := "https://aur.archlinux.org/rpc/v5/info/" + suggestions[0] searchUrl := "https://aur.archlinux.org/rpc/v5/info/" + suggestions[0]
_, body, errs = request.Get(searchUrl).End() resp, err := client.R().SetSuccessResult(&searchMap).Get(searchUrl)
if err != nil {
if len(errs) > 0 {
fmt.Println("searchUrl err:", errs)
return "服务器网络错误!" return "服务器网络错误!"
} }
defer resp.Body.Close()
err = json.Unmarshal([]byte(body), &searchMap)
if err != nil {
fmt.Println("解析失败:", err)
}
searchResult = searchMap["results"].([]interface{})[0].(map[string]interface{}) searchResult = searchMap["results"].([]interface{})[0].(map[string]interface{})
} else { } else {
@ -98,15 +88,11 @@ func (a *Pkg) GetMsg() string {
var searchResults []map[string]interface{} var searchResults []map[string]interface{}
for _, suggestion := range suggestions { for _, suggestion := range suggestions {
searchUrl := "https://aur.archlinux.org/rpc/v5/info/" + suggestion searchUrl := "https://aur.archlinux.org/rpc/v5/info/" + suggestion
_, body, errs = request.Get(searchUrl).End() resp, err := client.R().SetSuccessResult(&searchMap).Get(searchUrl)
if len(errs) > 0 {
fmt.Println("searchUrl err:", errs)
}
err = json.Unmarshal([]byte(body), &searchMap)
if err != nil { if err != nil {
fmt.Println(err) return "服务器网络错误!"
} }
defer resp.Body.Close()
results := searchMap["results"].([]interface{}) results := searchMap["results"].([]interface{})
searchResults = append(searchResults, results[0].(map[string]interface{})) searchResults = append(searchResults, results[0].(map[string]interface{}))