mirror of
https://github.com/GlueOps/autoglue.git
synced 2026-02-13 21:00:06 +01:00
Refactor routing logic (Chi can be a pain when you're managing large sets of routes, but its one of the better options when considering a potential gRPC future)
Upgrade API Generation to fully support OAS3.1
Update swagger interface to RapiDoc - the old swagger interface doesnt support OAS3.1 yet
Docs are now embedded as part of the UI - once logged in they pick up the cookies and org id from what gets set by the UI, but you can override it
Other updates include better portability of the db-studio
Signed-off-by: allanice001 <allanice001@gmail.com>
54 lines
1009 B
Go
54 lines
1009 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
pgapi "github.com/sosedoff/pgweb/pkg/api"
|
|
pgclient "github.com/sosedoff/pgweb/pkg/client"
|
|
pgcmd "github.com/sosedoff/pgweb/pkg/command"
|
|
)
|
|
|
|
func MountDbStudio(dbURL, prefix string, readonly bool) (http.Handler, error) {
|
|
// Normalize prefix for pgweb:
|
|
// - no leading slash
|
|
// - always trailing slash if not empty
|
|
prefix = strings.Trim(prefix, "/")
|
|
if prefix != "" {
|
|
prefix = prefix + "/"
|
|
}
|
|
|
|
pgcmd.Opts = pgcmd.Options{
|
|
URL: dbURL,
|
|
Prefix: prefix, // e.g. "db-studio/"
|
|
ReadOnly: readonly,
|
|
Sessions: false,
|
|
LockSession: true,
|
|
SkipOpen: true,
|
|
}
|
|
|
|
cli, err := pgclient.NewFromUrl(dbURL, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if readonly {
|
|
_ = cli.SetReadOnlyMode()
|
|
}
|
|
|
|
if err := cli.Test(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pgapi.DbClient = cli
|
|
|
|
gin.SetMode(gin.ReleaseMode)
|
|
g := gin.New()
|
|
g.Use(gin.Recovery())
|
|
|
|
pgapi.SetupRoutes(g)
|
|
pgapi.SetupMetrics(g)
|
|
|
|
return g, nil
|
|
}
|