diff --git a/.gitignore b/.gitignore index a41301d..e6e4d75 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,11 @@ *.dylib *.test *.out -vendor/ -build/ go.work go.work.sum .env +vendor/ +build/ + +# Ignore build files from wasmbuild +pkg/manager/httphandler/frontend diff --git a/Makefile b/Makefile index 1ff4a2d..27bd110 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,6 @@ DOCKER ?= $(shell which docker 2>/dev/null) WASMBUILD ?= $(shell which wasmbuild 2>/dev/null) BUILDDIR ?= build CMDDIR=$(wildcard cmd/*) -WASMDIR=$(wildcard wasm/*) # Set OS and Architecture ARCH ?= $(shell arch | tr A-Z a-z | sed 's/x86_64/amd64/' | sed 's/i386/amd64/' | sed 's/armv7l/arm/' | sed 's/aarch64/arm64/') @@ -35,18 +34,13 @@ $(CMDDIR): go-dep mkdir @rm -rf ${BUILDDIR}/$(shell basename $@) @$(GO) build -tags frontend $(BUILD_FLAGS) -o ${BUILDDIR}/$(shell basename $@) ./$@ -# Rules for building -.PHONY: $(WASMDIR) -$(WASMDIR): go-dep wasmbuild-dep mkdir - @echo 'wasmbuild $@' - @$(GO) get github.com/djthorpe/go-wasmbuild/pkg/bootstrap github.com/djthorpe/go-wasmbuild/pkg/bootstrap/extra github.com/djthorpe/go-wasmbuild/pkg/mvc - @${WASMBUILD} build --go-flags='$(BUILD_FLAGS)' -o ${BUILDDIR}/wasm/$(shell basename $@) ./$@ && \ - mv ${BUILDDIR}/wasm/$(shell basename $@)/wasm_exec.html ${BUILDDIR}/wasm/$(shell basename $@)/index.html && \ - cp etc/embed.go ${BUILDDIR}/wasm/$(shell basename $@)/ - # Build pgmanager with embedded frontend .PHONY: pgmanager -pgmanager: wasm/pgmanager cmd/pgmanager +pgmanager: go-dep wasmbuild-dep tidy mkdir + @echo 'go generate frontend' + @$(GO) generate -tags frontend ./pkg/manager/httphandler/... + @echo 'go build cmd/pgmanager' + @$(GO) build -tags frontend $(BUILD_FLAGS) -o ${BUILDDIR}/pgmanager ./cmd/pgmanager # Build the docker image .PHONY: docker @@ -84,11 +78,8 @@ mkdir: @install -d $(BUILDDIR) .PHONY: go-dep tidy -tidy: mkdir +tidy: @echo 'go tidy' - @install -d ${BUILDDIR}/wasm/pgmanager - @cp -n etc/embed.go ${BUILDDIR}/wasm/pgmanager/ 2>/dev/null || true - @echo 'module github.com/mutablelogic/go-pg/build/wasm/pgmanager' > ${BUILDDIR}/wasm/pgmanager/go.mod @$(GO) mod tidy .PHONY: clean diff --git a/README.md b/README.md index 8543500..5631f02 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Postgresql Support for Go, built on top of [pgx](https://github.com/jackc/pgx). * Easy semantics for Insert, Delete, Update, Get and List operations; * Bulk insert operations and transactions; * Support for tracing and observability; -* [PostgreSQL Manager](pkg/manager/README.md) for server administration with REST API and Prometheus metrics; +* [PostgreSQL Manager](pkg/manager/README.md) for server administration with REST API, an optional frontend and prometheus metrics; * [Testing utilities](pkg/test/README.md) for integration testing with testcontainers. Documentation: diff --git a/go.mod b/go.mod index 3007ce2..51d8418 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/docker/go-connections v0.6.0 github.com/jackc/pgx/v5 v5.7.6 github.com/mutablelogic/go-client v1.2.2 - github.com/mutablelogic/go-pg/build/wasm/pgmanager v0.0.0-00010101000000-000000000000 github.com/mutablelogic/go-server v1.5.17 github.com/prometheus/client_golang v1.23.2 github.com/stretchr/testify v1.11.1 @@ -44,7 +43,6 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/google/uuid v1.6.0 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect @@ -78,23 +76,19 @@ require ( go.opentelemetry.io/auto/sdk v1.2.1 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.64.0 // indirect go.opentelemetry.io/otel v1.39.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.39.0 // indirect go.opentelemetry.io/otel/metric v1.39.0 // indirect go.opentelemetry.io/otel/trace v1.39.0 // indirect + go.opentelemetry.io/proto/otlp v1.9.0 // indirect go.yaml.in/yaml/v2 v2.4.3 // indirect golang.org/x/crypto v0.46.0 // indirect golang.org/x/net v0.47.0 // indirect golang.org/x/sync v0.19.0 // indirect golang.org/x/sys v0.39.0 // indirect golang.org/x/text v0.32.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 // indirect - google.golang.org/grpc v1.75.1 // indirect google.golang.org/protobuf v1.36.11 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) // Redirect old module path to this module (for transitive dependencies) replace github.com/djthorpe/go-pg => ./ - -// Frontend embedded files (local path, built by make wasm/pgmanager) -replace github.com/mutablelogic/go-pg/build/wasm/pgmanager => ./build/wasm/pgmanager diff --git a/pkg/manager/httphandler/frontend.go b/pkg/manager/httphandler/frontend.go deleted file mode 100644 index 346ba84..0000000 --- a/pkg/manager/httphandler/frontend.go +++ /dev/null @@ -1,17 +0,0 @@ -//go:build frontend - -package httphandler - -import ( - "net/http" - - // Packages - frontend "github.com/mutablelogic/go-pg/build/wasm/pgmanager" -) - -// RegisterFrontendHandler registers the frontend static file handler -func RegisterFrontendHandler(router *http.ServeMux, prefix string) { - // Serve static files - fileServer := http.FileServer(http.FS(frontend.FS)) - router.Handle(joinPath(prefix, "/"), http.StripPrefix(prefix, fileServer)) -} diff --git a/pkg/manager/httphandler/frontend_included.go b/pkg/manager/httphandler/frontend_included.go new file mode 100644 index 0000000..e6fddc2 --- /dev/null +++ b/pkg/manager/httphandler/frontend_included.go @@ -0,0 +1,26 @@ +//go:build frontend + +//go:generate sh -c "wasmbuild build -o frontend ../../../wasm/pgmanager && mv frontend/wasm_exec.html frontend/index.html" + +package httphandler + +import ( + "embed" + "io/fs" + "net/http" +) + +//go:embed frontend/* +var frontendFS embed.FS + +// RegisterFrontendHandler registers the frontend static file handler +func RegisterFrontendHandler(router *http.ServeMux, prefix string) { + // Get the subdirectory to strip the "frontend" prefix + subFS, err := fs.Sub(frontendFS, "frontend") + if err != nil { + panic(err) + } + + // Serve static files from the embedded frontend folder + router.Handle(joinPath(prefix, "/"), http.StripPrefix(prefix, http.FileServer(http.FS(subFS)))) +}