Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
fcb1a7813a | |||
6f1bc3d65b | |||
2b93c9d4c9 |
@ -131,12 +131,14 @@ func (r *Resolver) resolveIP(m *D.Msg) (msg *D.Msg, err error) {
|
|||||||
return nil, errors.New("GeoIP can't use")
|
return nil, errors.New("GeoIP can't use")
|
||||||
}
|
}
|
||||||
|
|
||||||
ips, _ := r.msgToIP(res.Msg)
|
ips, err := r.msgToIP(res.Msg)
|
||||||
|
if err == nil {
|
||||||
if record, _ := mmdb.Country(ips[0]); record.Country.IsoCode == "CN" || record.Country.IsoCode == "" {
|
if record, _ := mmdb.Country(ips[0]); record.Country.IsoCode == "CN" || record.Country.IsoCode == "" {
|
||||||
// release channel
|
// release channel
|
||||||
go func() { <-fallbackMsg }()
|
go func() { <-fallbackMsg }()
|
||||||
msg = res.Msg
|
msg = res.Msg
|
||||||
return
|
return msg, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,21 +174,13 @@ func (r *Resolver) msgToIP(msg *D.Msg) ([]net.IP, error) {
|
|||||||
var ips []net.IP
|
var ips []net.IP
|
||||||
|
|
||||||
for _, answer := range msg.Answer {
|
for _, answer := range msg.Answer {
|
||||||
if r.ipv6 {
|
switch ans := answer.(type) {
|
||||||
ans, ok := answer.(*D.AAAA)
|
case *D.AAAA:
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
ips = append(ips, ans.AAAA)
|
ips = append(ips, ans.AAAA)
|
||||||
continue
|
case *D.A:
|
||||||
}
|
|
||||||
|
|
||||||
ans, ok := answer.(*D.A)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
ips = append(ips, ans.A)
|
ips = append(ips, ans.A)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(ips) == 0 {
|
if len(ips) == 0 {
|
||||||
return nil, errors.New("Can't parse msg")
|
return nil, errors.New("Can't parse msg")
|
||||||
|
@ -36,7 +36,7 @@ func Start(addr string, secret string) {
|
|||||||
|
|
||||||
cors := cors.New(cors.Options{
|
cors := cors.New(cors.Options{
|
||||||
AllowedOrigins: []string{"*"},
|
AllowedOrigins: []string{"*"},
|
||||||
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
|
||||||
AllowedHeaders: []string{"Content-Type", "Authorization"},
|
AllowedHeaders: []string{"Content-Type", "Authorization"},
|
||||||
MaxAge: 300,
|
MaxAge: 300,
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user