dstm2014
2016-06-07 09:47
浏览 37
已采纳

Golang:脚本中的go命令?

I got a script written in Golang that I do not quite understand. I want to know why he wrote go server.Start() inside the script? Why not simply write server.Start?

package main

import (
    "github.com/miekg/dns"
    "testing"
    "time"
)

const TEST_ADDR = "127.0.0.1:9953"

func TestDNSResponse(t *testing.T) {
    server := NewDNSServer(&Config{
        dnsAddr: TEST_ADDR,
    })
    go server.Start()

    // Allow some time for server to start
    time.Sleep(150 * time.Millisecond)

    m := new(dns.Msg)
    m.Id = dns.Id()
    m.Question = []dns.Question{
        dns.Question{"docker.", dns.TypeA, dns.ClassINET},
    }
    c := new(dns.Client)
    _, _, err := c.Exchange(m, TEST_ADDR)

    if err != nil {
        t.Error("Error response from the server", err)
    }

    server.Stop()

    c = new(dns.Client)
    _, _, err = c.Exchange(m, TEST_ADDR)

    if err == nil {
        t.Error("Server still running but should be shut down.")
    }
}
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题