mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-02-26 16:57:08 +00:00
30 lines
666 B
Go
30 lines
666 B
Go
package dns
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/metacubex/mihomo/component/resolver"
|
|
icontext "github.com/metacubex/mihomo/context"
|
|
D "github.com/miekg/dns"
|
|
)
|
|
|
|
type Service struct {
|
|
handler handler
|
|
}
|
|
|
|
// ServeMsg implement [resolver.Service] ResolveMsg
|
|
func (s *Service) ServeMsg(ctx context.Context, msg *D.Msg) (*D.Msg, error) {
|
|
if len(msg.Question) == 0 {
|
|
return nil, errors.New("at least one question is required")
|
|
}
|
|
|
|
return s.handler(icontext.NewDNSContext(ctx), msg)
|
|
}
|
|
|
|
var _ resolver.Service = (*Service)(nil)
|
|
|
|
func NewService(resolver *Resolver, mapper *ResolverEnhancer) *Service {
|
|
return &Service{handler: newHandler(resolver, mapper)}
|
|
}
|