Skip to content

Commit a9e37e1

Browse files
committed
Add version endpoint
1 parent e4d1aeb commit a9e37e1

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

cmd/root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"github.com/thecasualcoder/dobby/pkg/config"
45
"github.com/urfave/cli"
56
"log"
67
)
@@ -17,7 +18,7 @@ func Run(args []string) error {
1718
app.Description = "Web app which obey's invokers action"
1819
app.Usage = "Waiting to serve the order"
1920
app.Name = "dobby"
20-
app.Version = BuildVersion()
21+
app.Version = config.BuildVersion()
2122

2223
app.Commands = []cli.Command{
2324
serverCmd(),

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"github.com/thecasualcoder/dobby/cmd"
5+
"github.com/thecasualcoder/dobby/pkg/config"
56
"log"
67
"os"
78
)
@@ -10,7 +11,7 @@ var majorVersion string
1011
var minorVersion string
1112

1213
func main() {
13-
cmd.SetBuildVersion(majorVersion, minorVersion)
14+
config.SetBuildVersion(majorVersion, minorVersion)
1415
err := cmd.Run(os.Args)
1516
if err != nil {
1617
log.Fatal(err)

cmd/version.go renamed to pkg/config/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cmd
1+
package config
22

33
import "fmt"
44

pkg/handler/handler.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package handler
2+
3+
import (
4+
"github.com/gin-gonic/gin"
5+
"github.com/thecasualcoder/dobby/pkg/config"
6+
"os"
7+
)
8+
9+
// Health return the dobby health status
10+
func Health(c *gin.Context) {
11+
c.JSON(200, gin.H{"healthy": true})
12+
}
13+
14+
// Version return dobby version
15+
func Version(c *gin.Context) {
16+
envVersion := os.Getenv("VERSION")
17+
version := config.BuildVersion()
18+
if envVersion != "" {
19+
version = envVersion
20+
}
21+
c.JSON(200, gin.H{"version": version})
22+
}

pkg/handler/ping.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

pkg/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ func Run(bindAddress, port string) error {
1111
r := gin.Default()
1212

1313
r.GET("/health", handler.Health)
14+
r.GET("/version", handler.Version)
1415
return r.Run(fmt.Sprintf("%s:%s", bindAddress, port))
1516
}

0 commit comments

Comments
 (0)