mirror of
https://github.com/coredns/coredns.git
synced 2025-12-09 03:45:11 -05:00
Golint2 (#280)
* Fix linter errors * More linting fixes * More docs and making members private that dont need to be public * Fix linter errors * More linting fixes * More docs and making members private that dont need to be public * More lint fixes This leaves: ~~~ middleware/kubernetes/nametemplate/nametemplate.go:64:6: exported type NameTemplate should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:71:1: exported method NameTemplate.SetTemplate should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:108:1: exported method NameTemplate.GetZoneFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:116:1: exported method NameTemplate.GetNamespaceFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:120:1: exported method NameTemplate.GetServiceFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:124:1: exported method NameTemplate.GetTypeFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:135:1: exported method NameTemplate.GetSymbolFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:167:1: exported method NameTemplate.IsValid should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:182:6: exported type NameValues should have comment or be unexported middleware/kubernetes/util/util.go:1:1: package comment should be of the form "Package util ..." middleware/kubernetes/util/util.go:27:2: exported const WildcardStar should have comment (or a comment on this block) or be unexported middleware/proxy/lookup.go:66:1: exported method Proxy.Forward should have comment or be unexported middleware/proxy/proxy.go:24:6: exported type Client should have comment or be unexported middleware/proxy/proxy.go:107:1: exported function Clients should have comment or be unexported middleware/proxy/reverseproxy.go:10:6: exported type ReverseProxy should have comment or be unexported middleware/proxy/reverseproxy.go:16:1: exported method ReverseProxy.ServeDNS should have comment or be unexported middleware/proxy/upstream.go:42:6: exported type Options should have comment or be unexported ~~~ I plan on reworking the proxy anyway, so I'll leave that be.
This commit is contained in:
@@ -10,32 +10,33 @@ import (
|
||||
|
||||
var once sync.Once
|
||||
|
||||
type Health struct {
|
||||
type health struct {
|
||||
Addr string
|
||||
|
||||
ln net.Listener
|
||||
mux *http.ServeMux
|
||||
}
|
||||
|
||||
func health(w http.ResponseWriter, r *http.Request) {
|
||||
io.WriteString(w, ok)
|
||||
}
|
||||
|
||||
func (h *Health) Startup() error {
|
||||
func (h *health) Startup() error {
|
||||
if h.Addr == "" {
|
||||
h.Addr = defAddr
|
||||
}
|
||||
|
||||
once.Do(func() {
|
||||
if ln, err := net.Listen("tcp", h.Addr); err != nil {
|
||||
ln, err := net.Listen("tcp", h.Addr)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Failed to start health handler: %s", err)
|
||||
return
|
||||
} else {
|
||||
h.ln = ln
|
||||
}
|
||||
|
||||
h.ln = ln
|
||||
|
||||
h.mux = http.NewServeMux()
|
||||
|
||||
h.mux.HandleFunc(path, health)
|
||||
h.mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
|
||||
io.WriteString(w, ok)
|
||||
})
|
||||
|
||||
go func() {
|
||||
http.Serve(h.ln, h.mux)
|
||||
}()
|
||||
@@ -43,7 +44,7 @@ func (h *Health) Startup() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *Health) Shutdown() error {
|
||||
func (h *health) Shutdown() error {
|
||||
if h.ln != nil {
|
||||
return h.ln.Close()
|
||||
}
|
||||
|
||||
@@ -10,14 +10,14 @@ import (
|
||||
func TestHealth(t *testing.T) {
|
||||
// We use a random port instead of a fixed port like 8080 that may have been
|
||||
// occupied by some other process.
|
||||
health := Health{Addr: ":0"}
|
||||
if err := health.Startup(); err != nil {
|
||||
h := health{Addr: ":0"}
|
||||
if err := h.Startup(); err != nil {
|
||||
t.Fatalf("Unable to startup the health server: %v", err)
|
||||
}
|
||||
defer health.Shutdown()
|
||||
defer h.Shutdown()
|
||||
|
||||
// Reconstruct the http address based on the port allocated by operating system.
|
||||
address := fmt.Sprintf("http://%s%s", health.ln.Addr().String(), path)
|
||||
address := fmt.Sprintf("http://%s%s", h.ln.Addr().String(), path)
|
||||
|
||||
response, err := http.Get(address)
|
||||
if err != nil {
|
||||
|
||||
@@ -19,9 +19,9 @@ func setup(c *caddy.Controller) error {
|
||||
return middleware.Error("health", err)
|
||||
}
|
||||
|
||||
health := &Health{Addr: addr}
|
||||
c.OnStartup(health.Startup)
|
||||
c.OnShutdown(health.Shutdown)
|
||||
h := &health{Addr: addr}
|
||||
c.OnStartup(h.Startup)
|
||||
c.OnShutdown(h.Shutdown)
|
||||
|
||||
// Don't do AddMiddleware, as health is not *really* a middleware just a separate
|
||||
// webserver running.
|
||||
|
||||
Reference in New Issue
Block a user