douwen7475 2019-01-25 05:09
浏览 69
已采纳

如何为网络程序包设置DNS缓存?

In the "net/http" package I can cache the DNS lookups by:

client := &http.Client{
        Transport: &http.Transport{
            Dial: (&nett.Dialer{
                Resolver: &nett.CacheResolver{TTL: 5 * time.Minute},
                IPFilter: nett.DualStack,
            }).Dial,
        },

    }

then use client to retrieve websites. How do I cache the DNS lookups for the net package? for instance, a reverse DNS request:

net.LookupAddr(ip)

Since this does not use a variable I am confused as to how to get it setup and how to even know if I am using a cached instance.

  • 写回答

2条回答 默认 最新

  • douxin8383 2019-01-25 09:02
    关注

    The nett package seems to just have a single "Resolve" method rather than LookupAddr, LookupIP etc etc that the official net package has. So reverse lookups don't seem to be available. Here's how to do a normal lookup of address from name

    package main
    
    import (
        "github.com/abursavich/nett"
        "time"
    )
    
    func main() {
        r := nett.CacheResolver{TTL: 5 * time.Minute}
        a, _ := r.Resolve("muppet.com")
        for _, i := range a {
            print(i.String())
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 WPF动态创建页面内容
  • ¥15 如何对TBSS的结果进行统计学的分析已完成置换检验,如何在最终的TBSS输出结果提取除具体值及如何做进一步相关性分析
  • ¥15 SQL数据库操作问题
  • ¥100 关于lm339比较电路出现的问题
  • ¥15 Matlab安装yalmip和cplex功能安装失败
  • ¥15 加装宝马安卓中控改变开机画面
  • ¥15 STK安装问题问问大家,这种情况应该怎么办
  • ¥15 关于罗技鼠标宏lua文件的问题
  • ¥15 halcon ocr mlp 识别问题
  • ¥15 已知曲线满足正余弦函数,根据其峰值,还原出整条曲线