giddy

DNS queries and hostname resolution for gleam’s erlang and javascript targets by wrapping their native networking libraries.

Package Version Hex Docs

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.

  1. The javascript target uses promises from gleam_javascript. So while the giddy.gethostbyname_erl function returns Result(List(LookupResponse), error.GiddyError), the giddy.gethostbyname_js function returns Promise(Result(List(LookupResponse), error.GiddyError)). That’s why the functions have different names on the different targets, because the return types don’t match.
  2. They don’t support the same DNS record types. You can query the available types with the giddy.is_supported_js and giddy.is_supported_erl functions.

Development

gleam run   # Run the project
gleam test  # Run the tests
✨ Search Document