giddy
DNS queries and hostname resolution for gleam’s erlang and javascript targets by wrapping their native networking libraries.
using
gleam add giddy@0.1
import gleam/javascript/promise // only needed for javascript target
import giddy
@target(javascript)
pub fn main() {
use result <- promise.map(gleam.gethostbyname_js("localhost", Some(giddy.V4)))
echo result
use result <- promise.map(resolve_js("example.com", giddy.Aaaa))
echo result
}
@target(erlang)
pub fn main() {
echo gethostbyname_erl("localhost", Some(giddy.V6))
echo resolve_erl("example.com", giddy.Aaaa)
}
Further documentation can be found at https://giddy.hexdocs.pm/.
caveats
There are some differences between the javascript and erlang targets.
- The javascript target uses promises from gleam_javascript. So while the
giddy.gethostbyname_erlfunction returnsResult(List(LookupResponse), error.GiddyError), thegiddy.gethostbyname_jsfunction returnsPromise(Result(List(LookupResponse), error.GiddyError)). That’s why the functions have different names on the different targets, because the return types don’t match. - They don’t support the same DNS record types. You can query the available types with the
giddy.is_supported_jsandgiddy.is_supported_erlfunctions.
- Supported javascript record types:
AAAAAANYCAACNAMEMXNAPTRNSPTRSOASRVTXTTLSA
- Supported erlang record types:
AAAAAANYCAACNAMEGIDHINFOMBMDMGMFMINFOMXNAPTRNSNULLPTRSOASPFSRVTXTUIDUINFOUNSPECWKS
Development
gleam run # Run the project
gleam test # Run the tests