fix 修复sync.map可能为空panic的bug

This commit is contained in:
timerzz 2024-12-11 13:54:03 +08:00
parent d1b5ebef94
commit 09ffb5bb89
3 changed files with 12 additions and 3 deletions

3
go.mod
View File

@ -3,7 +3,7 @@ module gitea.timerzz.com/kedaya_haitao/common
go 1.22.5
require (
gitea.timerzz.com/timerzz/proxy-detector v0.0.0-20241211052219-23dc1eaeff85
gitea.timerzz.com/timerzz/proxy-detector v0.0.0-20241211054555-5b102469a2a4
github.com/bytedance/sonic v1.11.6
github.com/cloudwego/hertz v0.9.1
github.com/corpix/uarand v0.2.0
@ -114,6 +114,7 @@ require (
github.com/onsi/ginkgo/v2 v2.9.5 // indirect
github.com/openacid/low v0.1.21 // indirect
github.com/oschwald/maxminddb-golang v1.12.0 // indirect
github.com/panjf2000/ants/v2 v2.10.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.1 // indirect
github.com/pierrec/lz4/v4 v4.1.14 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect

6
go.sum
View File

@ -1,5 +1,7 @@
gitea.timerzz.com/timerzz/proxy-detector v0.0.0-20241211052219-23dc1eaeff85 h1:jE6OMbnyQIiSSAuG7szEbqCpHvYJk5d3M4QPDSM3G2c=
gitea.timerzz.com/timerzz/proxy-detector v0.0.0-20241211052219-23dc1eaeff85/go.mod h1:rM4P/hjc96PZaeQNf0qYYZ+r1IxuRil1BAZcqoO2Q6Y=
gitea.timerzz.com/timerzz/proxy-detector v0.0.0-20241211054555-5b102469a2a4 h1:5Pws6UwWWknqezsATzLZnLwpo7g4hNRYoCVBUj76jA8=
gitea.timerzz.com/timerzz/proxy-detector v0.0.0-20241211054555-5b102469a2a4/go.mod h1:rM4P/hjc96PZaeQNf0qYYZ+r1IxuRil1BAZcqoO2Q6Y=
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/RyuaNerin/elliptic2 v1.0.0/go.mod h1:wWB8fWrJI/6EPJkyV/r1Rj0hxUgrusmqSj8JN6yNf/A=
@ -256,6 +258,8 @@ github.com/openacid/must v0.1.3/go.mod h1:luPiXCuJlEo3UUFQngVQokV0MPGryeYvtCbQPs
github.com/openacid/testkeys v0.1.6/go.mod h1:MfA7cACzBpbiwekivj8StqX0WIRmqlMsci1c37CA3Do=
github.com/oschwald/maxminddb-golang v1.12.0 h1:9FnTOD0YOhP7DGxGsq4glzpGy5+w7pq50AS6wALUMYs=
github.com/oschwald/maxminddb-golang v1.12.0/go.mod h1:q0Nob5lTCqyQ8WT6FYgS1L7PXKVVbgiymefNwIjPzgY=
github.com/panjf2000/ants/v2 v2.10.0 h1:zhRg1pQUtkyRiOFo2Sbqwjp0GfBNo9cUY2/Grpx1p+8=
github.com/panjf2000/ants/v2 v2.10.0/go.mod h1:7ZxyxsqE4vvW0M7LSD8aI3cKwgFhBHbxnlN8mDqHa1I=
github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg=
github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pierrec/lz4/v4 v4.1.14 h1:+fL8AQEZtz/ijeNnpduH0bROTu0O3NZAlPjQxGn8LwE=
@ -323,6 +327,7 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
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.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
@ -401,6 +406,7 @@ golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
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.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

View File

@ -15,7 +15,7 @@ import (
)
type Pool struct {
proxies structs.Proxies
proxies *structs.Proxies
cfg *Option
updated time.Time
}
@ -32,7 +32,9 @@ func InitDefaultProxyPool() (*Pool, error) {
return NewProxyPool(cfg), nil
}
func NewProxyPool(cfg *Option) *Pool {
var p = &Pool{}
var p = &Pool{
proxies: structs.NewProxies([]structs.Proxy{}),
}
p.cfg = cfg
p.Update()
return p