diff options
Diffstat (limited to 'nix/templates/goapp/backend')
-rw-r--r-- | nix/templates/goapp/backend/default.nix | 21 | ||||
-rw-r--r-- | nix/templates/goapp/backend/go.mod | 5 | ||||
-rw-r--r-- | nix/templates/goapp/backend/go.sum | 2 | ||||
-rw-r--r-- | nix/templates/goapp/backend/src/main.go | 29 |
4 files changed, 57 insertions, 0 deletions
diff --git a/nix/templates/goapp/backend/default.nix b/nix/templates/goapp/backend/default.nix new file mode 100644 index 0000000..1156621 --- /dev/null +++ b/nix/templates/goapp/backend/default.nix @@ -0,0 +1,21 @@ +{ pkgs, packagename, ... }: + +let + version = "0.0.1"; +in +pkgs.buildGoModule { + name = "${packagename}-${version}"; + pname = "${packagename}"; + version = "${version}"; + + src = ./.; + subPackages = [ "src" ]; + vendorHash = "sha256-8wYERVt3PIsKkarkwPu8Zy/Sdx43P6g2lz2xRfvTZ2E="; + + postInstall = '' + mkdir -p $out + mv $out/bin/src $out/bin/${packagename} + ''; + + doCheck = true; +} diff --git a/nix/templates/goapp/backend/go.mod b/nix/templates/goapp/backend/go.mod new file mode 100644 index 0000000..41401c9 --- /dev/null +++ b/nix/templates/goapp/backend/go.mod @@ -0,0 +1,5 @@ +module github.com/hanemile/goapp/backend + +go 1.23.5 + +require github.com/gorilla/mux v1.8.1 diff --git a/nix/templates/goapp/backend/go.sum b/nix/templates/goapp/backend/go.sum new file mode 100644 index 0000000..7128337 --- /dev/null +++ b/nix/templates/goapp/backend/go.sum @@ -0,0 +1,2 @@ +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= 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()) +} |