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
15 changes: 9 additions & 6 deletions cmd/pgmanager/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"net/http"

// Packages
"github.com/mutablelogic/go-pg"
"github.com/mutablelogic/go-pg/pkg/manager"
"github.com/mutablelogic/go-pg/pkg/manager/httphandler"
"github.com/mutablelogic/go-server/pkg/httpserver"
pg "github.com/mutablelogic/go-pg"
manager "github.com/mutablelogic/go-pg/pkg/manager"
httphandler "github.com/mutablelogic/go-pg/pkg/manager/httphandler"
version "github.com/mutablelogic/go-pg/pkg/version"
httpserver "github.com/mutablelogic/go-server/pkg/httpserver"
)

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -22,6 +23,7 @@ type ServerCommands struct {

type RunServer struct {
URL string `arg:"" name:"url" help:"Database URL" default:""`
UI bool `name:"ui" help:"Enable frontend UI" default:"false"`

// Postgres options
PG struct {
Expand Down Expand Up @@ -75,7 +77,7 @@ func (cmd *RunServer) Run(ctx *Globals) error {
// Register HTTP handlers
router := http.NewServeMux()
httphandler.RegisterBackendHandlers(router, ctx.HTTP.Prefix, manager)
httphandler.RegisterFrontendHandler(router, "")
httphandler.RegisterFrontendHandler(router, "", cmd.UI)

// Create a TLS config
var tlsconfig *tls.Config
Expand All @@ -93,6 +95,7 @@ func (cmd *RunServer) Run(ctx *Globals) error {
}

// Run the server
fmt.Println("Starting server on", ctx.HTTP.Addr)
fmt.Println(version.ExecName(), version.Version())
fmt.Println("Listening on", ctx.HTTP.Addr+ctx.HTTP.Prefix)
return server.Run(ctx.ctx)
}
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ 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 @@ -76,16 +77,17 @@ 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
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/httphandler/frontend_excluded.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// RegisterFrontendHandler registers a fallback handler when frontend is not included
func RegisterFrontendHandler(router *http.ServeMux, prefix string) {
func RegisterFrontendHandler(router *http.ServeMux, prefix string, enabled bool) {
// Catch all handler returns a "not found" error
router.HandleFunc(joinPath(prefix, "/"), func(w http.ResponseWriter, r *http.Request) {
_ = httpresponse.Error(w, httpresponse.ErrNotFound, r.URL.String())
Expand Down
16 changes: 14 additions & 2 deletions pkg/manager/httphandler/frontend_included.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@ import (
"embed"
"io/fs"
"net/http"

// Packages
"github.com/mutablelogic/go-server/pkg/httpresponse"
)

//go:embed frontend/*
var frontendFS embed.FS

// RegisterFrontendHandler registers the frontend static file handler
func RegisterFrontendHandler(router *http.ServeMux, prefix string) {
// RegisterFrontendHandler registers the frontend static file handler if enabled,
// otherwise registers a fallback handler that returns a not found error.
func RegisterFrontendHandler(router *http.ServeMux, prefix string, enabled bool) {
if !enabled {
// Fallback handler returns a "not found" error
router.HandleFunc(joinPath(prefix, "/"), func(w http.ResponseWriter, r *http.Request) {
_ = httpresponse.Error(w, httpresponse.ErrNotFound, r.URL.String())
})
return
}

// Get the subdirectory to strip the "frontend" prefix
subFS, err := fs.Sub(frontendFS, "frontend")
if err != nil {
Expand Down
14 changes: 13 additions & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package version

import "runtime"
import (
"os"
"path/filepath"
"runtime"
)

///////////////////////////////////////////////////////////////////////////////
// GLOBALS
Expand All @@ -16,6 +20,14 @@ var (
////////////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS

func ExecName() string {
name, err := os.Executable()
if err != nil {
return "unknown"
}
return filepath.Base(name)
}

func Version() string {
if GitTag != "" {
return GitTag
Expand Down