Skip to content
This repository has been archived by the owner on Jan 24, 2019. It is now read-only.

Commit

Permalink
Merge pull request #365 from travisofthenorth/fix/default-http-address
Browse files Browse the repository at this point in the history
Fix url parse error
  • Loading branch information
jehiah authored Apr 20, 2017
2 parents 120a47a + f983933 commit f511cac
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log"
"net"
"net/http"
"net/url"
"strings"
"time"
)
Expand All @@ -24,19 +23,24 @@ func (s *Server) ListenAndServe() {
}

func (s *Server) ServeHTTP() {
u, err := url.Parse(s.Opts.HttpAddress)
if err != nil {
log.Fatalf("FATAL: could not parse %#v: %v", s.Opts.HttpAddress, err)
httpAddress := s.Opts.HttpAddress
scheme := ""

i := strings.Index(httpAddress, "://")
if i > -1 {
scheme = httpAddress[0:i]
}

var networkType string
switch u.Scheme {
switch scheme {
case "", "http":
networkType = "tcp"
default:
networkType = u.Scheme
networkType = scheme
}
listenAddr := strings.TrimPrefix(u.String(), u.Scheme+"://")

slice := strings.SplitN(httpAddress, "//", 2)
listenAddr := slice[len(slice)-1]

listener, err := net.Listen(networkType, listenAddr)
if err != nil {
Expand Down

0 comments on commit f511cac

Please sign in to comment.