Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Split DNS host from host:port
Browse files Browse the repository at this point in the history
  • Loading branch information
bboreham committed Sep 6, 2018
1 parent dd9593b commit 52f42cd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion nameserver/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nameserver
import (
"encoding/json"
"fmt"
"net"
"net/http"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -87,6 +88,11 @@ func (n *Nameserver) HandleHTTP(router *mux.Router, dockerCli *docker.Client) {

func (d *DNSServer) HandleHTTP(router *mux.Router) {
router.Methods("GET").Path("/dns-address").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, d.address)
host, _, err := net.SplitHostPort(d.address)
if err != nil {
http.Error(w, fmt.Sprintf("Error in DNS address %q: %v", d.address, err), http.StatusInternalServerError)
return
}
fmt.Fprint(w, host)
})
}

0 comments on commit 52f42cd

Please sign in to comment.