Added embed, nix, and a makefile
This commit is contained in:
@@ -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
|
||||
+3
-3
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user