cacheddns

package module
v0.0.0-...-9e58873 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2015 License: BSD-2-Clause Imports: 4 Imported by: 0

README

cacheddns

GoDoc

Get the IP of a domain, caching the result temporarily in memory.

Installation

go get github.com/ernestoalejo/cacheddns
Usage
package main

import (
  "log"
  "time"

  "github.com/ernestoalejo/cacheddns"
)

func main() {
  myDomain := cacheddns.New("www.google.com", 30*time.Second)

  // Will resolve the domain once every 30 seconds
  address, err := myDomain.Resolve()
  if err != nil {
    log.Fatal(err)
  }
}

Documentation

Overview

Package cacheddns resolves domains caching the result in memory to avoid hitting the DNS server too often.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CachedDomain

type CachedDomain struct {
	// contains filtered or unexported fields
}

CachedDomain stores info about the cached domain in memory.

func New

func New(domain string, ttl time.Duration) *CachedDomain

New creates a new cached domain in memory. This will NOT call the DNS server yet.

func (*CachedDomain) Get

func (c *CachedDomain) Get() (string, bool)

Get returns the currently cached address and a true flag. If it has not been resolved yet or the TTL has passed it will return an empty string with the flag set to false. It's recommended to use Resolve() directly instead.

func (*CachedDomain) Resolve

func (c *CachedDomain) Resolve() (string, error)

Resolve returns the cached address or checks with the DNS server the setting if the TTL has expired. It returns the first address found.

func (*CachedDomain) Update

func (c *CachedDomain) Update() (string, error)

Update the cached address if needed and return it. Any connection error will be returned. It's recommended to use Resolve() directly instead.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL