Code Monkey home page Code Monkey logo

go's Introduction

dnslink-std/go

The reference implementation for DNSLink in golang.

Usage

You can use dnslink both as code and as an CLI tool.

Golang API

Getting started with the dnslink in a jiffy:

import {
	dnslink "github.com/dnslink-std/go"
}

result, error := dnslink.Resolve("dnslink.dev")

if error != nil {
  switch e := error.(type) {
  default:
    // A variety other errors may be returned. Possible causes include, but are not limited to:
    // - Invalid input
    // - Timeouts / aborts
    // - Networking errors
    // - Incompatible dns packets provided by server
    panic(e)
  case dnslink.DNSRCodeError:
    err.DNSRCode // Error code number following - https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6
    err.Name // Error code name following (same list)
    err.Code // "RCODE_%s", err.RCode
    err.Domain // Domain lookup that resulted in the error
    if e.RCode == 3 {
      // NXDomain = Domain not found; most relevant error
    }
  }
}

// `links` property is a map[string][]string containing given links for the different keys, sorted.
result.Links["ipfs"][0] == "QmTg....yomU"

// The `log` is always an Array and contains a list of log entries
// that were should help to trace back how the linked data was resolved.
result.Log

// The `txtEntries` are a reduced form of the links that contains the namespace
// as part of the value.
result.TxtEntries === [{ value: "/ipfs/QmTg....yomU", ttl: 60 }]

You can configure the DNS resolution

import {
  "net"
  "context"
  "time"
}

resolver := &dnslink.Resolver{
  LookupTXT: dnslink.NewUDPLookup("1.1.1.1:53"),
}

// The resolver will now use googles 1.1.1.1 dns server.
resolver.Resolve("dnslink.dev")

Possible log statements

The dnslink.LogStatements in the log all follow the DNSLink specification.

Command Line

To get the command line tool you can either install it using go get

go get -u github.com/dnslink-std/go/dnslink

Or download a binary asset from the github release page.

You can get detailed help for the app by passing a --help option at the end:

dnslink --help

License

Published under dual-license: MIT OR Apache-2.0

go's People

Contributors

martinheidegger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

go's Issues

Example usage of --dns option does not work as described

dnslink --help prints (among others) these examples:

# Receive the dnslink entries for the dnslink.io domain.
> dnslink dnslink.dev
/ipfs/QmXNosdfz3WQUHncsYBTw7diwYzCibVhrJmEhNNaMPQBQF

and

# Receive the dnslink entries using the system DNS.
> dnslink --dns dnslink.dev
/ipfs/QmXNosdfz3WQUHncsYBTw7diwYzCibVhrJmEhNNaMPQBQF

This leads me to believe that dnslink does not use the system resolver by default (which I don't like) but specifying --dns does use the system resolver.
But executing the example dnslink --dns dnslink.dev just panics:

panic: invalid argument to Intn

goroutine 1 [running]:
math/rand.(*Rand).Intn(0x18?, 0x666a40?)
	math/rand/rand.go:180 +0x4c
math/rand.Intn(0xc000020258?)
	math/rand/rand.go:453 +0x25
main.main.NewUDPLookup.func1({0xc000020258, 0x14})
	github.com/dnslink-std/go/dnslink.go:244 +0x16c
github.com/dnslink-std/go.resolve(0xc0000e1ab0?, {0x7ffeff05e63f?, 0xb?})
	github.com/dnslink-std/go/dnslink.go:313 +0x156
github.com/dnslink-std/go.(*Resolver).Resolve(...)
	github.com/dnslink-std/go/dnslink.go:86
main.main()
	github.com/dnslink-std/go/dnslink/main.go:298 +0x9fa

Maybe not specifying the --dns option is what actually uses the system resolver and the documentation is just wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.