Update tailwind.config.js and .air.toml, remove stylegen/package.json and modify base.css and main.go
This commit is contained in:
parent
ac9082194c
commit
d9b0bc44fb
15 changed files with 134 additions and 25 deletions
|
@ -5,8 +5,8 @@ tmp_dir = "tmp"
|
||||||
[build]
|
[build]
|
||||||
args_bin = []
|
args_bin = []
|
||||||
bin = "./tmp/main"
|
bin = "./tmp/main"
|
||||||
pre_cmd = ["cd stylegen && bun i"]
|
pre_cmd = []
|
||||||
cmd = "go build -o ./tmp/main . & cd stylegen && bun gen"
|
cmd = "go build -o ./tmp/main . & cd stylegen && ./gen.sh"
|
||||||
delay = 1000
|
delay = 1000
|
||||||
exclude_dir = ["assets", "tmp", "vendor", "testdata", "stylegen"]
|
exclude_dir = ["assets", "tmp", "vendor", "testdata", "stylegen"]
|
||||||
exclude_file = []
|
exclude_file = []
|
||||||
|
|
55
main.go
55
main.go
|
@ -1,6 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/labstack/echo/v4/middleware"
|
"github.com/labstack/echo/v4/middleware"
|
||||||
|
@ -16,6 +25,9 @@ func main() {
|
||||||
// Initialize Echo router
|
// Initialize Echo router
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
|
|
||||||
|
// Generate a unique version identifier
|
||||||
|
version := time.Now().Format(time.RFC3339)
|
||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
e.Use(middleware.Logger())
|
e.Use(middleware.Logger())
|
||||||
e.Use(middleware.Recover())
|
e.Use(middleware.Recover())
|
||||||
|
@ -27,6 +39,40 @@ func main() {
|
||||||
Level: 5,
|
Level: 5,
|
||||||
}))
|
}))
|
||||||
e.Use(middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(50)))
|
e.Use(middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(50)))
|
||||||
|
// Use middleware to set ETag and Cache-Control headers
|
||||||
|
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
|
return func(c echo.Context) error {
|
||||||
|
// Get the path of the requested resource
|
||||||
|
path := c.Request().URL.Path
|
||||||
|
|
||||||
|
// If the requested resource is a CSS file
|
||||||
|
if strings.HasSuffix(path, ".css") {
|
||||||
|
log.Println(path)
|
||||||
|
// Read the CSS file
|
||||||
|
data, err := os.ReadFile(filepath.Join("public", strings.TrimPrefix(path, "/public")))
|
||||||
|
if err != nil {
|
||||||
|
// Log the error and return a 500 status
|
||||||
|
log.Println(err)
|
||||||
|
return c.NoContent(http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute the hash of the CSS file contents
|
||||||
|
hash := sha256.Sum256(data)
|
||||||
|
|
||||||
|
// Set the ETag to the hash
|
||||||
|
c.Response().Header().Set("ETag", hex.EncodeToString(hash[:]))
|
||||||
|
|
||||||
|
// Set the Content-Type to text/css
|
||||||
|
c.Response().Header().Set("Content-Type", "text/css")
|
||||||
|
} else {
|
||||||
|
// For other resources, set the ETag to the server start time
|
||||||
|
c.Response().Header().Set("ETag", version)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Response().Header().Set("Cache-Control", "public, no-cache")
|
||||||
|
return next(c)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Static server
|
// Static server
|
||||||
e.Static("/public", "public")
|
e.Static("/public", "public")
|
||||||
|
@ -43,6 +89,11 @@ func main() {
|
||||||
apiGroup.GET("/sse", api.SSE)
|
apiGroup.GET("/sse", api.SSE)
|
||||||
apiGroup.POST("/sendsse", api.SSEDemoSend)
|
apiGroup.POST("/sendsse", api.SSEDemoSend)
|
||||||
|
|
||||||
// Start server
|
// Start server with HTTP/2 support
|
||||||
e.Logger.Fatal(e.Start(":3000"))
|
s := &http.Server{
|
||||||
|
Addr: ":3000",
|
||||||
|
Handler: e,
|
||||||
|
}
|
||||||
|
e.Logger.Fatal(e.StartServer(s))
|
||||||
|
log.Println("Server started on port 3000")
|
||||||
}
|
}
|
||||||
|
|
2
public/css/styles.css
vendored
2
public/css/styles.css
vendored
File diff suppressed because one or more lines are too long
17
stylegen/base.css
vendored
17
stylegen/base.css
vendored
|
@ -1,12 +1,15 @@
|
||||||
|
@import url('daisyui.css') layer(base);
|
||||||
@tailwind base;
|
@tailwind base;
|
||||||
@tailwind components;
|
@tailwind components;
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
|
||||||
html,
|
@layer base {
|
||||||
container,
|
html,
|
||||||
body {
|
container,
|
||||||
height: 100%;
|
body {
|
||||||
width: 100%;
|
height: 100%;
|
||||||
overflow-y: auto;
|
width: 100%;
|
||||||
position: fixed;
|
overflow-y: auto;
|
||||||
|
position: fixed;
|
||||||
|
}
|
||||||
}
|
}
|
Binary file not shown.
20
stylegen/daisyui.css
vendored
Normal file
20
stylegen/daisyui.css
vendored
Normal file
File diff suppressed because one or more lines are too long
46
stylegen/gen.sh
Executable file
46
stylegen/gen.sh
Executable file
|
@ -0,0 +1,46 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
OS=$(uname -s)
|
||||||
|
ARCH=$(uname -m)
|
||||||
|
|
||||||
|
# Normalize OS and ARCH identifiers
|
||||||
|
case $OS in
|
||||||
|
"Darwin")
|
||||||
|
OS="macos"
|
||||||
|
;;
|
||||||
|
"Linux")
|
||||||
|
OS="linux"
|
||||||
|
;;
|
||||||
|
"CYGWIN"*|"MINGW"*|"MSYS"*)
|
||||||
|
OS="windows"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown operating system: $OS"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case $ARCH in
|
||||||
|
"x86_64")
|
||||||
|
ARCH="x64"
|
||||||
|
;;
|
||||||
|
"arm64")
|
||||||
|
ARCH="arm64"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unsupported architecture: $ARCH"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Construct the binary file name
|
||||||
|
BINARY="./tw/${OS}-${ARCH}"
|
||||||
|
if [ "$OS" = "windows" ]; then
|
||||||
|
BINARY="${BINARY}.exe"
|
||||||
|
else
|
||||||
|
# Set execute permissions on the binary
|
||||||
|
chmod +x $BINARY
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run the binary
|
||||||
|
$BINARY build -i ./base.css -o ../public/css/styles.css --minify
|
|
@ -1,11 +0,0 @@
|
||||||
{
|
|
||||||
"scripts": {
|
|
||||||
"gen": "tailwindcss build ./base.css -o ../public/css/styles.css --minify",
|
|
||||||
"watch": "tailwindcss build ./base.css -o ../public/css/styles.css --watch --minify"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@tailwindcss/typography": "^0.5.10",
|
|
||||||
"daisyui": "^4.6.0",
|
|
||||||
"tailwindcss": "^3.4.1"
|
|
||||||
}
|
|
||||||
}
|
|
2
stylegen/tailwind.config.js
vendored
2
stylegen/tailwind.config.js
vendored
|
@ -7,6 +7,6 @@ module.exports = {
|
||||||
daisyui: {
|
daisyui: {
|
||||||
themes: ["night"],
|
themes: ["night"],
|
||||||
},
|
},
|
||||||
plugins: [require("daisyui"), require('@tailwindcss/typography')],
|
plugins: [require('@tailwindcss/typography')],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
BIN
stylegen/tw/linux-arm64
Normal file
BIN
stylegen/tw/linux-arm64
Normal file
Binary file not shown.
BIN
stylegen/tw/linux-x64
Normal file
BIN
stylegen/tw/linux-x64
Normal file
Binary file not shown.
BIN
stylegen/tw/macos-arm64
Executable file
BIN
stylegen/tw/macos-arm64
Executable file
Binary file not shown.
BIN
stylegen/tw/macos-x64
Normal file
BIN
stylegen/tw/macos-x64
Normal file
Binary file not shown.
BIN
stylegen/tw/windows-arm64.exe
Normal file
BIN
stylegen/tw/windows-arm64.exe
Normal file
Binary file not shown.
BIN
stylegen/tw/windows-x64.exe
Normal file
BIN
stylegen/tw/windows-x64.exe
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue