Skip to content

Commit

Permalink
Refactor http server to a separate package
Browse files Browse the repository at this point in the history
  • Loading branch information
caalberts committed Apr 11, 2018
1 parent 4c10312 commit df3150c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 3 additions & 5 deletions cmd/localghost/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package main

import (
"flag"
"fmt"
"net/http"

"github.com/caalberts/localghost/http"
)

var port = flag.String("p", "8080", "port number")

func main() {
flag.Parse()

fmt.Println("localghost:" + *port)
http.ListenAndServe(":"+*port, nil)
http.NewServer(*port).ListenAndServe()
}
11 changes: 11 additions & 0 deletions http/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package http

import (
"log"
"net/http"
)

func NewServer(port string) *http.Server {
log.Println("localghost:" + port)
return &http.Server{Addr: ":" + port}
}

0 comments on commit df3150c

Please sign in to comment.