mirror of
https://github.com/sosedoff/pgweb.git
synced 2024-12-15 03:36:33 +03:00
Move version definition into command package, include build timestamp, add /api/info endpoint
This commit is contained in:
parent
0bd5360315
commit
c0f3f027ae
3
Makefile
3
Makefile
@ -1,5 +1,6 @@
|
||||
TARGETS = darwin/amd64 darwin/386 linux/amd64 linux/386 windows/amd64 windows/386
|
||||
GIT_COMMIT = $(shell git rev-parse HEAD)
|
||||
BUILD_TIME = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" | tr -d '\n')
|
||||
DOCKER_RELEASE_TAG = "sosedoff/pgweb:$(shell git describe --abbrev=0 --tags | sed 's/v//')"
|
||||
BINDATA_IGNORE = $(shell git ls-files -io --exclude-standard $< | sed 's/^/-ignore=/;s/[.]/[.]/g')
|
||||
|
||||
@ -41,7 +42,7 @@ build: assets
|
||||
release: assets
|
||||
gox \
|
||||
-osarch="$(TARGETS)" \
|
||||
-ldflags "-X main.GitCommit $(GIT_COMMIT)" \
|
||||
-ldflags "-X github.com/sosedoff/pgweb/pkg/command.GitCommit $(GIT_COMMIT) -X github.com/sosedoff/pgweb/pkg/command.BuildTime $(BUILD_TIME)" \
|
||||
-output="./bin/pgweb_{{.OS}}_{{.Arch}}"
|
||||
|
||||
bootstrap:
|
||||
|
11
main.go
11
main.go
@ -14,11 +14,6 @@ import (
|
||||
"github.com/sosedoff/pgweb/pkg/util"
|
||||
)
|
||||
|
||||
const VERSION = "0.5.2"
|
||||
|
||||
// The git commit that was compiled. This will be filled in by the compiler.
|
||||
var GitCommit string
|
||||
|
||||
var options command.Options
|
||||
|
||||
func exitWithMessage(message string) {
|
||||
@ -72,9 +67,9 @@ func initOptions() {
|
||||
}
|
||||
|
||||
func printVersion() {
|
||||
str := fmt.Sprintf("Pgweb v%s", VERSION)
|
||||
if GitCommit != "" {
|
||||
str += fmt.Sprintf(" (git: %s)", GitCommit)
|
||||
str := fmt.Sprintf("Pgweb v%s", command.VERSION)
|
||||
if command.GitCommit != "" {
|
||||
str += fmt.Sprintf(" (git: %s)", command.GitCommit)
|
||||
}
|
||||
|
||||
fmt.Println(str)
|
||||
|
@ -197,3 +197,13 @@ func GetBookmarks(c *gin.Context) {
|
||||
bookmarks, err := bookmarks.ReadAll(bookmarks.Path())
|
||||
serveResult(bookmarks, err, c)
|
||||
}
|
||||
|
||||
func GetInfo(c *gin.Context) {
|
||||
info := map[string]string{
|
||||
"version": command.VERSION,
|
||||
"git_sha": command.GitCommit,
|
||||
"build_time": command.BuildTime,
|
||||
}
|
||||
|
||||
c.JSON(200, info)
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ func NewError(err error) Error {
|
||||
// Middleware function to check database connection status before running queries
|
||||
func dbCheckMiddleware() gin.HandlerFunc {
|
||||
allowedPaths := []string{
|
||||
"/api/info",
|
||||
"/api/connect",
|
||||
"/api/bookmarks",
|
||||
"/api/history",
|
||||
|
@ -12,6 +12,7 @@ func SetupRoutes(router *gin.Engine) {
|
||||
{
|
||||
api.Use(dbCheckMiddleware())
|
||||
|
||||
api.GET("/info", GetInfo)
|
||||
api.POST("/connect", Connect)
|
||||
api.GET("/databases", GetDatabases)
|
||||
api.GET("/connection", GetConnectionInfo)
|
||||
|
8
pkg/command/version.go
Normal file
8
pkg/command/version.go
Normal file
@ -0,0 +1,8 @@
|
||||
package command
|
||||
|
||||
const VERSION = "0.5.2"
|
||||
|
||||
var (
|
||||
GitCommit string
|
||||
BuildTime string
|
||||
)
|
Loading…
Reference in New Issue
Block a user