golint cleanup (#828)
Clean up some golint related issues. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
c08497adee
commit
7ca018374f
8 changed files with 23 additions and 18 deletions
|
@ -102,6 +102,8 @@ func (s *ServergRPC) OnStartupComplete() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop stops the server. It blocks until the server is
|
||||||
|
// totally stopped.
|
||||||
func (s *ServergRPC) Stop() (err error) {
|
func (s *ServergRPC) Stop() (err error) {
|
||||||
s.m.Lock()
|
s.m.Lock()
|
||||||
defer s.m.Unlock()
|
defer s.m.Unlock()
|
||||||
|
@ -144,6 +146,7 @@ func (s *ServergRPC) Query(ctx context.Context, in *pb.DnsPacket) (*pb.DnsPacket
|
||||||
return &pb.DnsPacket{Msg: packed}, nil
|
return &pb.DnsPacket{Msg: packed}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shutdown stops the server (non gracefully).
|
||||||
func (s *ServergRPC) Shutdown() error {
|
func (s *ServergRPC) Shutdown() error {
|
||||||
if s.grpcServer != nil {
|
if s.grpcServer != nil {
|
||||||
s.grpcServer.Stop()
|
s.grpcServer.Stop()
|
||||||
|
|
|
@ -9,24 +9,23 @@ import (
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
// serverTLS represents an instance of a TLS-over-DNS-server.
|
// ServerTLS represents an instance of a TLS-over-DNS-server.
|
||||||
type serverTLS struct {
|
type ServerTLS struct {
|
||||||
*Server
|
*Server
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServerTLS returns a new CoreDNS TLS server and compiles all middleware in to it.
|
// NewServerTLS returns a new CoreDNS TLS server and compiles all middleware in to it.
|
||||||
func NewServerTLS(addr string, group []*Config) (*serverTLS, error) {
|
func NewServerTLS(addr string, group []*Config) (*ServerTLS, error) {
|
||||||
|
|
||||||
s, err := NewServer(addr, group)
|
s, err := NewServer(addr, group)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &serverTLS{Server: s}, nil
|
return &ServerTLS{Server: s}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serve implements caddy.TCPServer interface.
|
// Serve implements caddy.TCPServer interface.
|
||||||
func (s *serverTLS) Serve(l net.Listener) error {
|
func (s *ServerTLS) Serve(l net.Listener) error {
|
||||||
s.m.Lock()
|
s.m.Lock()
|
||||||
|
|
||||||
// Only fill out the TCP server for this one.
|
// Only fill out the TCP server for this one.
|
||||||
|
@ -40,10 +39,10 @@ func (s *serverTLS) Serve(l net.Listener) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServePacket implements caddy.UDPServer interface.
|
// ServePacket implements caddy.UDPServer interface.
|
||||||
func (s *serverTLS) ServePacket(p net.PacketConn) error { return nil }
|
func (s *ServerTLS) ServePacket(p net.PacketConn) error { return nil }
|
||||||
|
|
||||||
// Listen implements caddy.TCPServer interface.
|
// Listen implements caddy.TCPServer interface.
|
||||||
func (s *serverTLS) Listen() (net.Listener, error) {
|
func (s *ServerTLS) Listen() (net.Listener, error) {
|
||||||
// The *tls* middleware must make sure that multiple conflicting
|
// The *tls* middleware must make sure that multiple conflicting
|
||||||
// TLS configuration return an error: it can only be specified once.
|
// TLS configuration return an error: it can only be specified once.
|
||||||
tlsConfig := new(tls.Config)
|
tlsConfig := new(tls.Config)
|
||||||
|
@ -70,11 +69,11 @@ func (s *serverTLS) Listen() (net.Listener, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenPacket implements caddy.UDPServer interface.
|
// ListenPacket implements caddy.UDPServer interface.
|
||||||
func (s *serverTLS) ListenPacket() (net.PacketConn, error) { return nil, nil }
|
func (s *ServerTLS) ListenPacket() (net.PacketConn, error) { return nil, nil }
|
||||||
|
|
||||||
// OnStartupComplete lists the sites served by this server
|
// OnStartupComplete lists the sites served by this server
|
||||||
// and any relevant information, assuming Quiet is false.
|
// and any relevant information, assuming Quiet is false.
|
||||||
func (s *serverTLS) OnStartupComplete() {
|
func (s *ServerTLS) OnStartupComplete() {
|
||||||
if Quiet {
|
if Quiet {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@ func NewZone(name, file string) *Zone {
|
||||||
return z
|
return z
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy copies a zone.
|
||||||
func (z *Zone) Copy() *Zone {
|
func (z *Zone) Copy() *Zone {
|
||||||
z1 := NewZone(z.origin, z.file)
|
z1 := NewZone(z.origin, z.file)
|
||||||
z1.TransferTo = z.TransferTo
|
z1.TransferTo = z.TransferTo
|
||||||
|
|
|
@ -14,7 +14,6 @@ import "github.com/miekg/dns"
|
||||||
// is NXDOMAIN (NameError). This is needed to support the AutoPath.OnNXDOMAIN
|
// is NXDOMAIN (NameError). This is needed to support the AutoPath.OnNXDOMAIN
|
||||||
// function, which returns a NOERROR to client instead of NXDOMAIN if the final
|
// function, which returns a NOERROR to client instead of NXDOMAIN if the final
|
||||||
// search in the path fails to produce results.
|
// search in the path fails to produce results.
|
||||||
|
|
||||||
type AutoPathWriter struct {
|
type AutoPathWriter struct {
|
||||||
dns.ResponseWriter
|
dns.ResponseWriter
|
||||||
original dns.Question
|
original dns.Question
|
||||||
|
|
|
@ -49,6 +49,7 @@ type Kubernetes struct {
|
||||||
interfaceAddrsFunc func() net.IP
|
interfaceAddrsFunc func() net.IP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AutoPath enables server side search path lookups for pods
|
||||||
type AutoPath struct {
|
type AutoPath struct {
|
||||||
Enabled bool
|
Enabled bool
|
||||||
NDots int
|
NDots int
|
||||||
|
@ -683,6 +684,8 @@ func splitSearch(zone, question, namespace string) (name, search string, ok bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// Svc is the DNS schema for kubernetes services
|
||||||
Svc = "svc"
|
Svc = "svc"
|
||||||
|
// Pod is the DNS schema for kubernetes pods
|
||||||
Pod = "pod"
|
Pod = "pod"
|
||||||
)
|
)
|
||||||
|
|
|
@ -106,7 +106,7 @@ func loadRoots(caPath string) (*x509.CertPool, error) {
|
||||||
return roots, nil
|
return roots, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetHTTPSTransport returns an HTTP transport configured using tls.Config
|
// NewHTTPSTransport returns an HTTP transport configured using tls.Config
|
||||||
func NewHTTPSTransport(cc *tls.Config) *http.Transport {
|
func NewHTTPSTransport(cc *tls.Config) *http.Transport {
|
||||||
// this seems like a bad idea but was here in the previous version
|
// this seems like a bad idea but was here in the previous version
|
||||||
if cc != nil {
|
if cc != nil {
|
||||||
|
|
|
@ -61,7 +61,7 @@ type UpstreamHost struct {
|
||||||
FailTimeout time.Duration
|
FailTimeout time.Duration
|
||||||
OkUntil time.Time
|
OkUntil time.Time
|
||||||
CheckDown UpstreamHostDownFunc
|
CheckDown UpstreamHostDownFunc
|
||||||
CheckUrl string
|
CheckURL string
|
||||||
WithoutPathPrefix string
|
WithoutPathPrefix string
|
||||||
Checking bool
|
Checking bool
|
||||||
checkMu sync.Mutex
|
checkMu sync.Mutex
|
||||||
|
|
|
@ -273,7 +273,7 @@ func parseBlock(c *caddyfile.Dispenser, u *staticUpstream) error {
|
||||||
// otherwise checks will back up, potentially a lot of them if a host is
|
// otherwise checks will back up, potentially a lot of them if a host is
|
||||||
// absent for a long time. This arrangement makes checks quickly see if
|
// absent for a long time. This arrangement makes checks quickly see if
|
||||||
// they are the only one running and abort otherwise.
|
// they are the only one running and abort otherwise.
|
||||||
func healthCheckUrl(nextTs time.Time, host *UpstreamHost) {
|
func healthCheckURL(nextTs time.Time, host *UpstreamHost) {
|
||||||
|
|
||||||
// lock for our bool check. We don't just defer the unlock because
|
// lock for our bool check. We don't just defer the unlock because
|
||||||
// we don't want the lock held while http.Get runs
|
// we don't want the lock held while http.Get runs
|
||||||
|
@ -294,7 +294,7 @@ func healthCheckUrl(nextTs time.Time, host *UpstreamHost) {
|
||||||
// when the remote host is not merely not serving, but actually
|
// when the remote host is not merely not serving, but actually
|
||||||
// absent, then tcp syn timeouts can be very long, and so one
|
// absent, then tcp syn timeouts can be very long, and so one
|
||||||
// fetch could last several check intervals
|
// fetch could last several check intervals
|
||||||
if r, err := http.Get(host.CheckUrl); err == nil {
|
if r, err := http.Get(host.CheckURL); err == nil {
|
||||||
io.Copy(ioutil.Discard, r.Body)
|
io.Copy(ioutil.Discard, r.Body)
|
||||||
r.Body.Close()
|
r.Body.Close()
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ func healthCheckUrl(nextTs time.Time, host *UpstreamHost) {
|
||||||
func (u *staticUpstream) healthCheck() {
|
func (u *staticUpstream) healthCheck() {
|
||||||
for _, host := range u.Hosts {
|
for _, host := range u.Hosts {
|
||||||
|
|
||||||
if host.CheckUrl == "" {
|
if host.CheckURL == "" {
|
||||||
var hostName, checkPort string
|
var hostName, checkPort string
|
||||||
|
|
||||||
// The DNS server might be an HTTP server. If so, extract its name.
|
// The DNS server might be an HTTP server. If so, extract its name.
|
||||||
|
@ -338,14 +338,14 @@ func (u *staticUpstream) healthCheck() {
|
||||||
checkPort = u.HealthCheck.Port
|
checkPort = u.HealthCheck.Port
|
||||||
}
|
}
|
||||||
|
|
||||||
host.CheckUrl = "http://" + net.JoinHostPort(checkHostName, checkPort) + u.HealthCheck.Path
|
host.CheckURL = "http://" + net.JoinHostPort(checkHostName, checkPort) + u.HealthCheck.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate this before the get
|
// calculate this before the get
|
||||||
nextTs := time.Now().Add(u.Future)
|
nextTs := time.Now().Add(u.Future)
|
||||||
|
|
||||||
// locks/bools should prevent requests backing up
|
// locks/bools should prevent requests backing up
|
||||||
go healthCheckUrl(nextTs, host)
|
go healthCheckURL(nextTs, host)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue