about summary refs log tree commit diff
path: root/nix/templates/goapp/frontend/src
diff options
context:
space:
mode:
authorEmile <git@emile.space>2025-02-12 21:24:31 +0100
committerEmile <git@emile.space>2025-02-12 21:24:31 +0100
commitc0a8852e4ec21f15c5a862201515518c3eee7734 (patch)
treeeb906ede104475df681d3b61ecae234d5bb67b62 /nix/templates/goapp/frontend/src
parent2e1c7e7c033a8d1819c65a65dbed71f884e2fec1 (diff)
template: a basic golang app template
This template allows building golang apps as well as a corresponding
docker container from the built package
Diffstat (limited to 'nix/templates/goapp/frontend/src')
-rw-r--r--nix/templates/goapp/frontend/src/main.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/nix/templates/goapp/frontend/src/main.go b/nix/templates/goapp/frontend/src/main.go
new file mode 100644
index 0000000..adb15cd
--- /dev/null
+++ b/nix/templates/goapp/frontend/src/main.go
@@ -0,0 +1,29 @@
+package main
+
+import (
+	"fmt"
+	"log"
+	"net/http"
+	"time"
+
+	"github.com/gorilla/mux"
+)
+
+func indexHandler(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprintf(w, "Hello World from the frontend")
+}
+
+func main() {
+	r := mux.NewRouter()
+	r.HandleFunc("/", indexHandler)
+
+	srv := &http.Server{
+		Handler:      r,
+		Addr:         ":8080",
+		WriteTimeout: 15 * time.Second,
+		ReadTimeout:  15 * time.Second,
+	}
+
+	log.Printf("[i] Running the server on %s", srv.Addr)
+	log.Fatal(srv.ListenAndServe())
+}