diff options
author | Emile <git@emile.space> | 2025-02-12 21:24:31 +0100 |
---|---|---|
committer | Emile <git@emile.space> | 2025-02-12 21:24:31 +0100 |
commit | c0a8852e4ec21f15c5a862201515518c3eee7734 (patch) | |
tree | eb906ede104475df681d3b61ecae234d5bb67b62 /nix/templates/goapp/backend/src/main.go | |
parent | 2e1c7e7c033a8d1819c65a65dbed71f884e2fec1 (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/backend/src/main.go')
-rw-r--r-- | nix/templates/goapp/backend/src/main.go | 29 |
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()) +} |