Add version information
This commit is contained in:
parent
07c5b9cf5a
commit
e3b065ff89
5 changed files with 44 additions and 6 deletions
|
@ -5,6 +5,7 @@ WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
RUN go build -o rove-server .
|
RUN go build -o rove-server -ldflags="-X version.Version=$(git describe --always --long --dirty)" .
|
||||||
|
|
||||||
|
CMD [ "./rove-server" ]
|
||||||
|
|
||||||
CMD "./rove-server"
|
|
7
main.go
7
main.go
|
@ -8,13 +8,20 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/mdiluz/rove/pkg/server"
|
"github.com/mdiluz/rove/pkg/server"
|
||||||
|
"github.com/mdiluz/rove/pkg/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ver = flag.Bool("version", false, "Display version number")
|
||||||
var port = flag.Int("port", 8080, "The port to host on")
|
var port = flag.Int("port", 8080, "The port to host on")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if *ver {
|
||||||
|
fmt.Println(version.Version)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
s := server.NewServer(
|
s := server.NewServer(
|
||||||
server.OptionPort(*port),
|
server.OptionPort(*port),
|
||||||
server.OptionPersistentData())
|
server.OptionPersistentData())
|
||||||
|
|
|
@ -6,18 +6,40 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/mdiluz/rove/pkg/accounts"
|
"github.com/mdiluz/rove/pkg/accounts"
|
||||||
|
"github.com/mdiluz/rove/pkg/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Route defines the information for a single path->function route
|
||||||
|
type Route struct {
|
||||||
|
path string
|
||||||
|
handler func(http.ResponseWriter, *http.Request)
|
||||||
|
}
|
||||||
|
|
||||||
// NewRouter sets up the server mux
|
// NewRouter sets up the server mux
|
||||||
func (s *Server) SetUpRouter() {
|
func (s *Server) SetUpRouter() {
|
||||||
|
|
||||||
|
// Array of all our routes
|
||||||
|
var routes = []Route{
|
||||||
|
{
|
||||||
|
path: "/status",
|
||||||
|
handler: s.HandleStatus,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/register",
|
||||||
|
handler: s.HandleRegister,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// Set up the handlers
|
// Set up the handlers
|
||||||
s.router.HandleFunc("/status", s.HandleStatus)
|
for _, route := range routes {
|
||||||
s.router.HandleFunc("/register", s.HandleRegister)
|
s.router.HandleFunc(route.path, route.handler)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatusResponse is a struct that contains information on the status of the server
|
// StatusResponse is a struct that contains information on the status of the server
|
||||||
type StatusResponse struct {
|
type StatusResponse struct {
|
||||||
Ready bool `json:"ready"`
|
Ready bool `json:"ready"`
|
||||||
|
Version string `json:"version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleStatus handles HTTP requests to the /status endpoint
|
// HandleStatus handles HTTP requests to the /status endpoint
|
||||||
|
@ -31,7 +53,8 @@ func (s *Server) HandleStatus(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = StatusResponse{
|
var response = StatusResponse{
|
||||||
Ready: true,
|
Ready: true,
|
||||||
|
Version: version.Version,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Be a good citizen and set the header for the return
|
// Be a good citizen and set the header for the return
|
||||||
|
|
|
@ -21,6 +21,10 @@ func TestHandleStatus(t *testing.T) {
|
||||||
if status.Ready != true {
|
if status.Ready != true {
|
||||||
t.Errorf("got false for /status")
|
t.Errorf("got false for /status")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(status.Version) == 0 {
|
||||||
|
t.Errorf("got empty version info")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHandleRegister(t *testing.T) {
|
func TestHandleRegister(t *testing.T) {
|
||||||
|
|
3
pkg/version/version.go
Normal file
3
pkg/version/version.go
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
var Version = "undefined"
|
Loading…
Add table
Reference in a new issue