Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 6 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <https://pkg.go.dev/github.com/mutablelogic/go-pg>
Expand Down
10 changes: 2 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
17 changes: 0 additions & 17 deletions pkg/manager/httphandler/frontend.go

This file was deleted.

26 changes: 26 additions & 0 deletions pkg/manager/httphandler/frontend_included.go
Original file line number Diff line number Diff line change
@@ -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))))
}