diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2019-12-14 09:51:15 -0500 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2019-12-14 09:51:15 -0500 |
| commit | b2056fbf48849e321389977e3fdbb0f5841822c4 (patch) | |
| tree | 0f0b993d1f2ea0221067e4f689e606e33ba47bbd /cmd/server/main.go | |
| parent | c19536be6e4f8733af329204a50ffc254a679ee5 (diff) | |
| download | go-website-b2056fbf48849e321389977e3fdbb0f5841822c4.tar.gz go-website-b2056fbf48849e321389977e3fdbb0f5841822c4.tar.xz | |
Tidy up the server command, pull the handlers into the page library. Convert to go modules. Add a build script and version to the command
Diffstat (limited to 'cmd/server/main.go')
| -rw-r--r-- | cmd/server/main.go | 32 |
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) } |
