about summary refs log tree commit diff
path: root/nix/templates/goapp/backend/src
diff options
context:
space:
mode:
Diffstat (limited to 'nix/templates/goapp/backend/src')
-rw-r--r--nix/templates/goapp/backend/src/main.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/nix/templates/goapp/backend/src/main.go b/nix/templates/goapp/backend/src/main.go
new file mode 100644
index 0000000..b9d9214
--- /dev/null
+++ b/nix/templates/goapp/backend/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 backend")
+}
+
+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())
+}