41 lines
640 B
Go
41 lines
640 B
Go
package dethnote
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/urfave/negroni"
|
|
)
|
|
|
|
// Server is the master struct for the web app.
|
|
type Server struct {
|
|
root string
|
|
debug bool
|
|
|
|
n *negroni.Negroni
|
|
r *mux.Router
|
|
}
|
|
|
|
// NewServer initializes the server struct.
|
|
func NewServer(root string, debug bool) *Server {
|
|
return &Server{
|
|
root: root,
|
|
debug: debug,
|
|
}
|
|
}
|
|
|
|
// SetupHTTP configures the HTTP server.
|
|
func (s *Server) SetupHTTP() {
|
|
// Set up the router.
|
|
r := mux.NewRouter()
|
|
s.r = r
|
|
|
|
n := negroni.Classic()
|
|
n.UseHandler(r)
|
|
}
|
|
|
|
// Run the server.
|
|
func (s *Server) Run(addr string) {
|
|
http.ListenAndServe(addr, s.r)
|
|
}
|