Move version definition into command package, include build timestamp, add /api/info endpoint

This commit is contained in:
Dan Sosedoff 2015-05-05 00:34:23 -05:00
parent 0bd5360315
commit c0f3f027ae
6 changed files with 25 additions and 9 deletions

View File

@ -1,5 +1,6 @@
TARGETS = darwin/amd64 darwin/386 linux/amd64 linux/386 windows/amd64 windows/386 TARGETS = darwin/amd64 darwin/386 linux/amd64 linux/386 windows/amd64 windows/386
GIT_COMMIT = $(shell git rev-parse HEAD) 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//')" 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') BINDATA_IGNORE = $(shell git ls-files -io --exclude-standard $< | sed 's/^/-ignore=/;s/[.]/[.]/g')
@ -41,7 +42,7 @@ build: assets
release: assets release: assets
gox \ gox \
-osarch="$(TARGETS)" \ -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}}" -output="./bin/pgweb_{{.OS}}_{{.Arch}}"
bootstrap: bootstrap:

11
main.go
View File

@ -14,11 +14,6 @@ import (
"github.com/sosedoff/pgweb/pkg/util" "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 var options command.Options
func exitWithMessage(message string) { func exitWithMessage(message string) {
@ -72,9 +67,9 @@ func initOptions() {
} }
func printVersion() { func printVersion() {
str := fmt.Sprintf("Pgweb v%s", VERSION) str := fmt.Sprintf("Pgweb v%s", command.VERSION)
if GitCommit != "" { if command.GitCommit != "" {
str += fmt.Sprintf(" (git: %s)", GitCommit) str += fmt.Sprintf(" (git: %s)", command.GitCommit)
} }
fmt.Println(str) fmt.Println(str)

View File

@ -197,3 +197,13 @@ func GetBookmarks(c *gin.Context) {
bookmarks, err := bookmarks.ReadAll(bookmarks.Path()) bookmarks, err := bookmarks.ReadAll(bookmarks.Path())
serveResult(bookmarks, err, c) 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)
}

View File

@ -43,6 +43,7 @@ func NewError(err error) Error {
// Middleware function to check database connection status before running queries // Middleware function to check database connection status before running queries
func dbCheckMiddleware() gin.HandlerFunc { func dbCheckMiddleware() gin.HandlerFunc {
allowedPaths := []string{ allowedPaths := []string{
"/api/info",
"/api/connect", "/api/connect",
"/api/bookmarks", "/api/bookmarks",
"/api/history", "/api/history",

View File

@ -12,6 +12,7 @@ func SetupRoutes(router *gin.Engine) {
{ {
api.Use(dbCheckMiddleware()) api.Use(dbCheckMiddleware())
api.GET("/info", GetInfo)
api.POST("/connect", Connect) api.POST("/connect", Connect)
api.GET("/databases", GetDatabases) api.GET("/databases", GetDatabases)
api.GET("/connection", GetConnectionInfo) api.GET("/connection", GetConnectionInfo)

8
pkg/command/version.go Normal file
View File

@ -0,0 +1,8 @@
package command
const VERSION = "0.5.2"
var (
GitCommit string
BuildTime string
)