diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2dffd08 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +.PHONY: dev build clean + +# Run the development server +dev: + go run main.go + +# Build the standalone binary +build: + go build -o sprintpadawan main.go + +# Clean the compiled binary +clean: + rm -f sprintpadawan diff --git a/api/templates.go b/api/templates.go index 4db0040..0a3c69f 100644 --- a/api/templates.go +++ b/api/templates.go @@ -4,16 +4,16 @@ import ( "context" "fmt" "html/template" + "io/fs" "log" "net/http" - "path/filepath" "sprintpadawan/lib" ) var templates *template.Template -func init() { +func InitTemplates(fsys fs.FS) { templates = template.Must(template.New("").Funcs(template.FuncMap{ "scaleToOptions": scaleToOptions, "derefInt": func(i *int) int { @@ -51,7 +51,7 @@ func init() { } return d, nil }, - }).ParseGlob(filepath.Join("templates", "*.html"))) + }).ParseFS(fsys, "templates/*.html")) } func isHTMX(r *http.Request) bool { diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..1368f54 --- /dev/null +++ b/flake.nix @@ -0,0 +1,39 @@ +{ + description = "SprintPadawan Go 1.26 development environment"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { + inherit system; + }; + in + { + devShells.default = pkgs.mkShell { + buildInputs = [ + pkgs.go + pkgs.gopls + pkgs.gotools + pkgs.go-tools + pkgs.gnumake + ]; + + shellHook = '' + echo "SprintPadawan Dev Environment Loaded" + go version + ''; + }; + } + ); +} diff --git a/main.go b/main.go index 6c67e67..246794f 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "embed" "log" "net/http" @@ -8,13 +9,17 @@ import ( "sprintpadawan/lib" ) +//go:embed static templates +var embeddedFiles embed.FS + func main() { lib.InitDB() + api.InitTemplates(embeddedFiles) mux := http.NewServeMux() // serve static assets - mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) + mux.Handle("/static/", http.FileServer(http.FS(embeddedFiles))) api.SetupRoutes(mux)