|
12345678910111213141516171819202122232425262728293031323334353637 |
- 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"
- )
-
- var portPtr = flag.Int("p", 8080, "Port to listen on.")
-
- func main() {
- // Parse config options
- 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)
- }
- }
|