From fc58861046fff32a99fa3b2377152cbdcc458a21 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Fri, 29 May 2026 16:35:12 +0000 Subject: [PATCH] add release compile flag for mapping mime types --- Makefile | 2 +- app/common/meta_debug.go | 56 +++++++++++++++++++++++++ app/common/{meta.go => meta_release.go} | 45 ++------------------ 3 files changed, 60 insertions(+), 43 deletions(-) create mode 100644 app/common/meta_debug.go rename app/common/{meta.go => meta_release.go} (63%) diff --git a/Makefile b/Makefile index a014114..7098afc 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ build: clean @echo "======================== Building Binary =======================" # resolve symbolic links in web by copying it into dist/web/ cp -rL web/ dist/web/ - CGO_ENABLED=0 go build -ldflags="-s -w" -v -o dist/ . + CGO_ENABLED=0 go build -tags release -ldflags="-s -w" -v -o dist/ . test: clean go run . diff --git a/app/common/meta_debug.go b/app/common/meta_debug.go new file mode 100644 index 0000000..9762b19 --- /dev/null +++ b/app/common/meta_debug.go @@ -0,0 +1,56 @@ +//go:build !release +// +build !release + +package common + +import ( + "io" + + "github.com/tdewolff/minify/v2" +) + +// defines mime type and associated minifier +type MimeType struct { + Type string + Minifier func(m *minify.M, w io.Writer, r io.Reader, params map[string]string) error +} + +// debug mime types +var MimeTypes = map[string]MimeType{ + "css": { + Type: "text/css", + Minifier: nil, + }, + "html": { + Type: "text/html", + Minifier: nil, + }, + "tmpl": { + Type: "text/plain", + Minifier: nil, + }, + "frag": { + Type: "text/plain", + Minifier: nil, + }, + "svg": { + Type: "image/svg+xml", + Minifier: nil, + }, + "png": { + Type: "image/png", + Minifier: nil, + }, + "js": { + Type: "application/javascript", + Minifier: nil, + }, + "wasm": { + Type: "application/wasm", + Minifier: nil, + }, + "*": { + Type: "text/plain", + Minifier: nil, + }, +} diff --git a/app/common/meta.go b/app/common/meta_release.go similarity index 63% rename from app/common/meta.go rename to app/common/meta_release.go index 5b77bb2..416db3f 100644 --- a/app/common/meta.go +++ b/app/common/meta_release.go @@ -1,3 +1,6 @@ +//go:build release +// +build release + package common import ( @@ -55,45 +58,3 @@ var MimeTypes = map[string]MimeType{ Minifier: nil, }, } - -// debug mime types -/* -var MimeTypes = map[string]MimeType{ - "css": { - Type: "text/css", - Minifier: nil, - }, - "html": { - Type: "text/html", - Minifier: nil, - }, - "tmpl": { - Type: "text/plain", - Minifier: nil, - }, - "frag": { - Type: "text/plain", - Minifier: nil, - }, - "svg": { - Type: "image/svg+xml", - Minifier: nil, - }, - "png": { - Type: "image/png", - Minifier: nil, - }, - "js": { - Type: "application/javascript", - Minifier: nil, - }, - "wasm": { - Type: "application/wasm", - Minifier: nil, - }, - "*": { - Type: "text/plain", - Minifier: nil, - }, -} -*/