Created
April 23, 2017 10:36
-
-
Save eamonnmcevoy/72c390d2ac3794f0eca3b9afb621a499 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package server | |
import ( | |
"go_web_server/pkg" | |
"log" | |
"net/http" | |
"os" | |
"github.com/gorilla/handlers" | |
"github.com/gorilla/mux" | |
) | |
type Server struct { | |
router *mux.Router | |
} | |
func NewServer(u root.UserService) *Server { | |
s := Server{router: mux.NewRouter()} | |
NewUserRouter(u, s.newSubrouter("/user")) | |
return &s | |
} | |
func (s *Server) Start() { | |
log.Println("Listening on port 8080") | |
if err := http.ListenAndServe(":8080", handlers.LoggingHandler(os.Stdout, s.router)); err != nil { | |
log.Fatal("http.ListenAndServe: ", err) | |
} | |
} | |
func (s *Server) newSubrouter(path string) *mux.Router { | |
return s.router.PathPrefix(path).Subrouter() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment