First go at it :) #1
@@ -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"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"sprintpadawan/lib"
|
"sprintpadawan/lib"
|
||||||
)
|
)
|
||||||
|
|
||||||
var templates *template.Template
|
var templates *template.Template
|
||||||
|
|
||||||
func init() {
|
func InitTemplates(fsys fs.FS) {
|
||||||
templates = template.Must(template.New("").Funcs(template.FuncMap{
|
templates = template.Must(template.New("").Funcs(template.FuncMap{
|
||||||
"scaleToOptions": scaleToOptions,
|
"scaleToOptions": scaleToOptions,
|
||||||
"derefInt": func(i *int) int {
|
"derefInt": func(i *int) int {
|
||||||
@@ -51,7 +51,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
return d, nil
|
return d, nil
|
||||||
},
|
},
|
||||||
}).ParseGlob(filepath.Join("templates", "*.html")))
|
}).ParseFS(fsys, "templates/*.html"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func isHTMX(r *http.Request) bool {
|
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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@@ -8,13 +9,17 @@ import (
|
|||||||
"sprintpadawan/lib"
|
"sprintpadawan/lib"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed static templates
|
||||||
|
var embeddedFiles embed.FS
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
lib.InitDB()
|
lib.InitDB()
|
||||||
|
api.InitTemplates(embeddedFiles)
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
// serve static assets
|
// 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)
|
api.SetupRoutes(mux)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user