diff options
author | xengineering <mail2xengineering@protonmail.com> | 2021-06-11 09:06:56 +0200 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2021-06-11 09:12:06 +0200 |
commit | d93959de9f7ffd061dc57bec7c532829f592bf77 (patch) | |
tree | 5b6986d280a06d5671ed8657427ab87d1873742a | |
parent | 5ee9c18acf25ca06dfacdb857edbd54b8454b7e8 (diff) | |
download | birdscan-d93959de9f7ffd061dc57bec7c532829f592bf77.tar birdscan-d93959de9f7ffd061dc57bec7c532829f592bf77.tar.zst birdscan-d93959de9f7ffd061dc57bec7c532829f592bf77.zip |
Implement Web Server
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | data/html/index.html | 32 | ||||
-rw-r--r-- | src/go.mod | 2 | ||||
-rw-r--r-- | src/go.sum | 2 | ||||
-rw-r--r-- | src/main.go | 1 | ||||
-rw-r--r-- | src/web.go | 31 |
6 files changed, 69 insertions, 0 deletions
@@ -18,4 +18,5 @@ install: all make -C src install DESTDIR=$(abspath $(DESTDIR)) install -Dm 644 systemd/birdscan.service $(DESTDIR)$(PREFIX)/lib/systemd/system/birdscan.service install -Dm 644 systemd/birdscan.sysusers $(DESTDIR)$(PREFIX)/lib/sysusers.d/birdscan.conf + install -Dm 644 data/html/index.html $(DESTDIR)$(PREFIX)/share/birdscan/html/index.html diff --git a/data/html/index.html b/data/html/index.html new file mode 100644 index 0000000..af72c46 --- /dev/null +++ b/data/html/index.html @@ -0,0 +1,32 @@ +<!DOCTYPE html> + +<!-- + vim: shiftwidth=4 tabstop=4 noexpandtab +--> + +<html> + + <head> + + <title>birdscan</title> + + <meta charset="utf-8"/> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <link rel="stylesheet" href="./css/birdscan.css" type="text/css"> + + </head> + + <body> + + <nav> + <a href="https://xengineering.eu">xengineering</a> + </nav> + + <main> + <h1>birdscan</h1> + <p>A software to take beautiful pictures of birds with a Raspberry Pi Camera.</p> + </main> + + </body> + +</html> @@ -1,3 +1,5 @@ module src.xengineering.eu/xengineering/birdscan go 1.16 + +require github.com/go-chi/chi/v5 v5.0.3 // indirect diff --git a/src/go.sum b/src/go.sum new file mode 100644 index 0000000..e92da3f --- /dev/null +++ b/src/go.sum @@ -0,0 +1,2 @@ +github.com/go-chi/chi/v5 v5.0.3 h1:khYQBdPivkYG1s1TAzDQG1f6eX4kD2TItYVZexL5rS4= +github.com/go-chi/chi/v5 v5.0.3/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= diff --git a/src/main.go b/src/main.go index 7b693ee..5de338a 100644 --- a/src/main.go +++ b/src/main.go @@ -9,6 +9,7 @@ import ( func main() { log.Println("Starting birdscan") + go runServer() for { time.Sleep(1 * time.Second) } diff --git a/src/web.go b/src/web.go new file mode 100644 index 0000000..c0732ad --- /dev/null +++ b/src/web.go @@ -0,0 +1,31 @@ +// vim: shiftwidth=4 tabstop=4 noexpandtab + +package main + +import ( + "fmt" + "log" + "net/http" + + "github.com/go-chi/chi/v5" + "github.com/go-chi/chi/v5/middleware" +) + +const ( + APP_DATA = "/usr/share/birdscan" +) + +func runServer() { + router := chi.NewRouter() + router.Use(middleware.Logger) + + router.Get("/", indexHandler) + + log.Println("Binding to 'http://" + "127.0.0.1" + ":" + "8080" + "'") + log.Fatal(http.ListenAndServe("127.0.0.1" + ":" + "8080", router)) +} + +func indexHandler(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, fmt.Sprintf("%s/html/index.html", APP_DATA)) +} + |