Tantalor93 / doh-go

DoH client written in Golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Release Go version License: MIT Tantalor93 lint codecov Go Report Card

doh-go

DoH client written in Golang with minimal dependencies, built on top of https://github.com/miekg/dns and standard http client (net/http) and based on DoH RFC

Usage in your project

add dependency

go get github.com/tantalor93/doh-go

Examples

// create client with default http.Client
c := doh.NewClient(nil)

// prepare payload
msg := dns.Msg{}
msg.SetQuestion("google.com.", dns.TypeA)

// send DNS query to Cloudflare Server over DoH using POST method
r, err := c.SendViaPost(context.Background(), "https://1.1.1.1/dns-query", &msg)
if err != nil {
    panic(err)
}

// do something with response
fmt.Println(dns.RcodeToString[r.Rcode])

// send DNS query to Cloudflare Server over DoH using GET method
r, err = c.SendViaGet(context.Background(), "https://1.1.1.1/dns-query", &msg)
if err != nil {
    panic(err)
}

// do something with response
fmt.Println(dns.RcodeToString[r.Rcode])

About

DoH client written in Golang

License:MIT License


Languages

Language:Go 98.6%Language:HTML 1.4%