aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/server/main.go32
1 files changed, 12 insertions, 20 deletions
diff --git a/cmd/server/main.go b/cmd/server/main.go
index 42eb449..c18aa55 100644
--- a/cmd/server/main.go
+++ b/cmd/server/main.go
@@ -6,40 +6,32 @@ import (
"log"
"net/http"
"os"
- "path/filepath"
"git.riedstra.us/mitch/go-website/page"
)
+var VersionString = ""
+
+func VersionPrint() {
+ fmt.Println(VersionString)
+ os.Exit(0)
+}
+
func main() {
fl := flag.NewFlagSet("Website", flag.ExitOnError)
listen := fl.String("l", "0.0.0.0:8001", "Listening address")
directory := fl.String("d", ".", "Directory to serve.")
+ version := fl.Bool("v", false, "Print the version then exit")
_ = fl.Parse(os.Args[1:])
- fmt.Println("vim-go")
+ if *version {
+ VersionPrint()
+ }
if err := os.Chdir(*directory); err != nil {
log.Fatal(err)
}
- http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
- u := r.URL.Path
- if u == "/" {
- u = "/index"
- }
- u = filepath.Join(".", u)
- log.Println(u)
-
- p := &page.Page{Name: u}
- err := p.Render(w)
- if err != nil {
- log.Println(err)
- http.Error(w, "Internal server error", 500)
- return
- }
-
- })
- http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
+ page.SetupHandlers()
_ = http.ListenAndServe(*listen, nil)
}