diff options
author | Aki <please@ignore.pl> | 2021-04-16 01:23:34 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2021-04-16 01:23:34 +0200 |
commit | 7f84074fe3117614281c1e6c93af21f3333d96c1 (patch) | |
tree | a29169fcd2344400d400ef5b874d2af2fb1d296e /derelict.go | |
parent | 74ec08a6c24951adf01bc45f1bfdf57ba71d5f6d (diff) | |
download | field-7f84074fe3117614281c1e6c93af21f3333d96c1.zip field-7f84074fe3117614281c1e6c93af21f3333d96c1.tar.gz field-7f84074fe3117614281c1e6c93af21f3333d96c1.tar.bz2 |
Added stub go server
Diffstat (limited to 'derelict.go')
-rw-r--r-- | derelict.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/derelict.go b/derelict.go new file mode 100644 index 0000000..2f5e8b3 --- /dev/null +++ b/derelict.go @@ -0,0 +1,40 @@ +package main + +import ( + "embed" + "github.com/gorilla/mux" + "html/template" + "log" + "net/http" + "os" +) + +//go:embed *.json *.css *.js *.svg +var content embed.FS + +//go:embed *.tmpl +var internal embed.FS + +var templates *template.Template + +func main() { + port := os.Getenv("DERELICTPORT") + if port == "" { + port = "8080" + } + templates = template.Must(template.ParseFS(internal, "*.tmpl")) + + router := mux.NewRouter() + router.HandleFunc("/", handleRecent).Methods("GET") + router.HandleFunc("/view", handleView).Queries("id", "{id:[_0-9]+}").Methods("GET") + router.PathPrefix("/").Handler(http.FileServer(http.FS(content))) + log.Fatal(http.ListenAndServe(":"+port, router)) +} + +func handleRecent(w http.ResponseWriter, r *http.Request) { + templates.ExecuteTemplate(w, "recent", "") +} + +func handleView(w http.ResponseWriter, r *http.Request) { + templates.ExecuteTemplate(w, "view", "") +} |