From c0a8852e4ec21f15c5a862201515518c3eee7734 Mon Sep 17 00:00:00 2001 From: Emile Date: Wed, 12 Feb 2025 21:24:31 +0100 Subject: template: a basic golang app template This template allows building golang apps as well as a corresponding docker container from the built package --- nix/templates/goapp/frontend/src/main.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 nix/templates/goapp/frontend/src/main.go (limited to 'nix/templates/goapp/frontend/src/main.go') 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()) +} -- cgit 1.4.1