2021-11-17 16:03:47 +08:00
|
|
|
package resolver
|
|
|
|
|
2022-11-12 13:18:36 +08:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
D "github.com/miekg/dns"
|
|
|
|
)
|
2021-11-17 16:03:47 +08:00
|
|
|
|
|
|
|
var DefaultLocalServer LocalServer
|
|
|
|
|
|
|
|
type LocalServer interface {
|
2022-11-12 13:18:36 +08:00
|
|
|
ServeMsg(ctx context.Context, msg *D.Msg) (*D.Msg, error)
|
2021-11-17 16:03:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ServeMsg with a dns.Msg, return resolve dns.Msg
|
2022-11-12 13:18:36 +08:00
|
|
|
func ServeMsg(ctx context.Context, msg *D.Msg) (*D.Msg, error) {
|
2021-11-17 16:03:47 +08:00
|
|
|
if server := DefaultLocalServer; server != nil {
|
2022-11-12 13:18:36 +08:00
|
|
|
return server.ServeMsg(ctx, msg)
|
2021-11-17 16:03:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil, ErrIPNotFound
|
|
|
|
}
|