Skip to content

Commit

Permalink
Merge pull request #110 from linkernetworks/johnlin/restful-version
Browse files Browse the repository at this point in the history
add server version

Former-commit-id: 266a6612a472943a93b0439525c26b1d6439b9ec [formerly 8d8194b]
Former-commit-id: 363cd0704cecbff621d0e79e8d2f43fa2b3597ef
  • Loading branch information
Hung-Wei Chiu authored Jul 19, 2018
2 parents 4773467 + d16f6ed commit 43180d7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## vortex server version
SERVER_VERSION = v0.1.0
## Folder content generated files
BUILD_FOLDER = ./build

Expand Down Expand Up @@ -43,7 +45,7 @@ govendor-sync:
src.build:
$(GO) build -v ./src/...
$(MKDIR_P) $(BUILD_FOLDER)/src/cmd/vortex/
$(GO) build -v -o $(BUILD_FOLDER)/src/cmd/vortex/vortex ./src/cmd/vortex/...
$(GO) build -v -o $(BUILD_FOLDER)/src/cmd/vortex/vortex -ldflags="-X github.com/linkernetworks/vortex/src/version.version="$(SERVER_VERSION) ./src/cmd/vortex/...

.PHONY: src.test
src.test:
Expand Down Expand Up @@ -100,4 +102,12 @@ apps.teardown:

.PHONY: dockerfiles.build
dockerfiles.build:
docker build --tag sdnvortex/vortex:latest --file ./dockerfiles/Dockerfile .
docker build --tag sdnvortex/vortex:$(SERVER_VERSION) --file ./dockerfiles/Dockerfile .

## git tag version ########################################

.PHONY: push.tag
push.tag:
@echo "Current git tag version:"$(SERVER_VERSION)
git tag $(SERVER_VERSION)
git push --tags
13 changes: 8 additions & 5 deletions src/server/handler_version.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package server

import (
"github.com/emicklei/go-restful"
"github.com/linkernetworks/vortex/src/serviceprovider"
"github.com/linkernetworks/vortex/src/version"
"github.com/linkernetworks/vortex/src/web"
)

func versionHandler(sp *serviceprovider.Container) restful.RouteFunction {
return func(req *restful.Request, resp *restful.Response) {
}
func versionHandler(ctx *web.Context) {
_, _, resp := ctx.ServiceProvider, ctx.Request, ctx.Response
resp.WriteEntity(ActionResponse{
Error: false,
Message: version.GetVersion(),
})
}
4 changes: 2 additions & 2 deletions src/server/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func (a *App) AppRoute() *mux.Router {

func newVersionService(sp *serviceprovider.Container) *restful.WebService {
webService := new(restful.WebService)
webService.Path("/v1/versions").Consumes(restful.MIME_JSON, restful.MIME_JSON).Produces(restful.MIME_JSON, restful.MIME_JSON)
webService.Route(webService.GET("/").To(versionHandler(sp)))
webService.Path("/v1/version").Consumes(restful.MIME_JSON, restful.MIME_JSON).Produces(restful.MIME_JSON, restful.MIME_JSON)
webService.Route(webService.GET("/").To(handler.RESTfulServiceHandler(sp, versionHandler)))
return webService
}

Expand Down
7 changes: 7 additions & 0 deletions src/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package version

var version string

func GetVersion() string {
return version
}

0 comments on commit 43180d7

Please sign in to comment.