Skip to content

Commit a559a9f

Browse files
authored
Merge pull request #18 from mutablelogic/djt/1217/frontend
Updated
2 parents fc0eb3c + beec556 commit a559a9f

File tree

6 files changed

+40
-43
lines changed

6 files changed

+40
-43
lines changed

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
*.dylib
66
*.test
77
*.out
8-
vendor/
9-
build/
108
go.work
119
go.work.sum
1210
.env
11+
vendor/
12+
build/
13+
14+
# Ignore build files from wasmbuild
15+
pkg/manager/httphandler/frontend

Makefile

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ DOCKER ?= $(shell which docker 2>/dev/null)
44
WASMBUILD ?= $(shell which wasmbuild 2>/dev/null)
55
BUILDDIR ?= build
66
CMDDIR=$(wildcard cmd/*)
7-
WASMDIR=$(wildcard wasm/*)
87

98
# Set OS and Architecture
109
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
3534
@rm -rf ${BUILDDIR}/$(shell basename $@)
3635
@$(GO) build -tags frontend $(BUILD_FLAGS) -o ${BUILDDIR}/$(shell basename $@) ./$@
3736

38-
# Rules for building
39-
.PHONY: $(WASMDIR)
40-
$(WASMDIR): go-dep wasmbuild-dep mkdir
41-
@echo 'wasmbuild $@'
42-
@$(GO) get github.com/djthorpe/go-wasmbuild/pkg/bootstrap github.com/djthorpe/go-wasmbuild/pkg/bootstrap/extra github.com/djthorpe/go-wasmbuild/pkg/mvc
43-
@${WASMBUILD} build --go-flags='$(BUILD_FLAGS)' -o ${BUILDDIR}/wasm/$(shell basename $@) ./$@ && \
44-
mv ${BUILDDIR}/wasm/$(shell basename $@)/wasm_exec.html ${BUILDDIR}/wasm/$(shell basename $@)/index.html && \
45-
cp etc/embed.go ${BUILDDIR}/wasm/$(shell basename $@)/
46-
4737
# Build pgmanager with embedded frontend
4838
.PHONY: pgmanager
49-
pgmanager: wasm/pgmanager cmd/pgmanager
39+
pgmanager: go-dep wasmbuild-dep tidy mkdir
40+
@echo 'go generate frontend'
41+
@$(GO) generate -tags frontend ./pkg/manager/httphandler/...
42+
@echo 'go build cmd/pgmanager'
43+
@$(GO) build -tags frontend $(BUILD_FLAGS) -o ${BUILDDIR}/pgmanager ./cmd/pgmanager
5044

5145
# Build the docker image
5246
.PHONY: docker
@@ -84,11 +78,8 @@ mkdir:
8478
@install -d $(BUILDDIR)
8579

8680
.PHONY: go-dep tidy
87-
tidy: mkdir
81+
tidy:
8882
@echo 'go tidy'
89-
@install -d ${BUILDDIR}/wasm/pgmanager
90-
@cp -n etc/embed.go ${BUILDDIR}/wasm/pgmanager/ 2>/dev/null || true
91-
@echo 'module github.com/mutablelogic/go-pg/build/wasm/pgmanager' > ${BUILDDIR}/wasm/pgmanager/go.mod
9283
@$(GO) mod tidy
9384

9485
.PHONY: clean

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Postgresql Support for Go, built on top of [pgx](https://github.com/jackc/pgx).
77
* Easy semantics for Insert, Delete, Update, Get and List operations;
88
* Bulk insert operations and transactions;
99
* Support for tracing and observability;
10-
* [PostgreSQL Manager](pkg/manager/README.md) for server administration with REST API and Prometheus metrics;
10+
* [PostgreSQL Manager](pkg/manager/README.md) for server administration with REST API, an optional frontend and prometheus metrics;
1111
* [Testing utilities](pkg/test/README.md) for integration testing with testcontainers.
1212

1313
Documentation: <https://pkg.go.dev/github.com/mutablelogic/go-pg>

go.mod

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ require (
1010
github.com/docker/go-connections v0.6.0
1111
github.com/jackc/pgx/v5 v5.7.6
1212
github.com/mutablelogic/go-client v1.2.2
13-
github.com/mutablelogic/go-pg/build/wasm/pgmanager v0.0.0-00010101000000-000000000000
1413
github.com/mutablelogic/go-server v1.5.17
1514
github.com/prometheus/client_golang v1.23.2
1615
github.com/stretchr/testify v1.11.1
@@ -44,7 +43,6 @@ require (
4443
github.com/go-logr/stdr v1.2.2 // indirect
4544
github.com/go-ole/go-ole v1.3.0 // indirect
4645
github.com/google/uuid v1.6.0 // indirect
47-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
4846
github.com/jackc/pgpassfile v1.0.0 // indirect
4947
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
5048
github.com/jackc/puddle/v2 v2.2.2 // indirect
@@ -78,23 +76,19 @@ require (
7876
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
7977
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.64.0 // indirect
8078
go.opentelemetry.io/otel v1.39.0 // indirect
79+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.39.0 // indirect
8180
go.opentelemetry.io/otel/metric v1.39.0 // indirect
8281
go.opentelemetry.io/otel/trace v1.39.0 // indirect
82+
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
8383
go.yaml.in/yaml/v2 v2.4.3 // indirect
8484
golang.org/x/crypto v0.46.0 // indirect
8585
golang.org/x/net v0.47.0 // indirect
8686
golang.org/x/sync v0.19.0 // indirect
8787
golang.org/x/sys v0.39.0 // indirect
8888
golang.org/x/text v0.32.0 // indirect
89-
google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 // indirect
90-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 // indirect
91-
google.golang.org/grpc v1.75.1 // indirect
9289
google.golang.org/protobuf v1.36.11 // indirect
9390
gopkg.in/yaml.v3 v3.0.1 // indirect
9491
)
9592

9693
// Redirect old module path to this module (for transitive dependencies)
9794
replace github.com/djthorpe/go-pg => ./
98-
99-
// Frontend embedded files (local path, built by make wasm/pgmanager)
100-
replace github.com/mutablelogic/go-pg/build/wasm/pgmanager => ./build/wasm/pgmanager

pkg/manager/httphandler/frontend.go

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//go:build frontend
2+
3+
//go:generate sh -c "wasmbuild build -o frontend ../../../wasm/pgmanager && mv frontend/wasm_exec.html frontend/index.html"
4+
5+
package httphandler
6+
7+
import (
8+
"embed"
9+
"io/fs"
10+
"net/http"
11+
)
12+
13+
//go:embed frontend/*
14+
var frontendFS embed.FS
15+
16+
// RegisterFrontendHandler registers the frontend static file handler
17+
func RegisterFrontendHandler(router *http.ServeMux, prefix string) {
18+
// Get the subdirectory to strip the "frontend" prefix
19+
subFS, err := fs.Sub(frontendFS, "frontend")
20+
if err != nil {
21+
panic(err)
22+
}
23+
24+
// Serve static files from the embedded frontend folder
25+
router.Handle(joinPath(prefix, "/"), http.StripPrefix(prefix, http.FileServer(http.FS(subFS))))
26+
}

0 commit comments

Comments
 (0)