37 lines
708 B
Go
37 lines
708 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"github.com/gorilla/mux"
|
|
"github.com/writeas/web-core/log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
const (
|
|
templatesDir = "templates"
|
|
pagesDir = "pages"
|
|
staticDir = "static"
|
|
)
|
|
|
|
func main() {
|
|
// Parse config options
|
|
portPtr := flag.Int("p", 8080, "Port to listen on.")
|
|
flag.Parse()
|
|
|
|
// Add routes
|
|
r := mux.NewRouter()
|
|
r.HandleFunc("/{page:[a-z]+}", viewPage)
|
|
r.HandleFunc("/", viewPage)
|
|
r.PathPrefix("/").Handler(http.FileServer(http.Dir(staticDir)))
|
|
|
|
// Start server
|
|
log.Info("Listening on http://localhost:%d", *portPtr)
|
|
err := http.ListenAndServe(fmt.Sprintf(":%d", *portPtr), r)
|
|
if err != nil {
|
|
log.Error("Unable to ListenAndServe: %s", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|