1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-28 13:48:49 +08:00

Unify service versioning

Services are versioned through top-level package. The package itself
contains an HTTP header that will be bound to the '/version' endpoint of
each of the available services.

Signed-off-by: Dejan Mijic <dejan@mainflux.com>
This commit is contained in:
Dejan Mijic 2017-09-23 15:52:39 +02:00
parent bdf5001072
commit 75a8cdfe3f
No known key found for this signature in database
GPG Key ID: 35CD2D6AB811FEFC
8 changed files with 29 additions and 66 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/cisco/senml"
kithttp "github.com/go-kit/kit/transport/http"
"github.com/go-zoo/bone"
"github.com/mainflux/mainflux"
adapter "github.com/mainflux/mainflux/http"
"github.com/mainflux/mainflux/writer"
"github.com/prometheus/client_golang/prometheus/promhttp"
@ -41,6 +42,7 @@ func MakeHandler(svc adapter.Service) http.Handler {
opts...,
))
r.GetFunc("/version", mainflux.Version())
r.Handle("/metrics", promhttp.Handler())
return r

View File

@ -7,17 +7,6 @@ import (
"github.com/mainflux/mainflux/manager"
)
func infoEndpoint(svc manager.Service) endpoint.Endpoint {
return func(_ context.Context, request interface{}) (interface{}, error) {
info, err := svc.Info()
if err != nil {
return nil, err
}
return infoRes{Version: info.Version}, nil
}
}
func registrationEndpoint(svc manager.Service) endpoint.Endpoint {
return func(_ context.Context, request interface{}) (interface{}, error) {
user := request.(manager.User)

View File

@ -15,25 +15,6 @@ type apiResponse interface {
empty() bool
}
// Info
type infoReq struct{}
type infoRes struct {
Version string `json:"version"`
}
func (res infoRes) headers() map[string]string {
return map[string]string{}
}
func (res infoRes) code() int {
return http.StatusOK
}
func (res infoRes) empty() bool {
return false
}
type clientReq struct {
key string
id string

View File

@ -7,6 +7,7 @@ import (
kithttp "github.com/go-kit/kit/transport/http"
"github.com/go-zoo/bone"
"github.com/mainflux/mainflux"
"github.com/mainflux/mainflux/manager"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
@ -19,13 +20,6 @@ func MakeHandler(svc manager.Service) http.Handler {
r := bone.New()
r.Get("/info", kithttp.NewServer(
infoEndpoint(svc),
decodeInfo,
encodeResponse,
opts...,
))
r.Post("/users", kithttp.NewServer(
registrationEndpoint(svc),
decodeCredentials,
@ -124,16 +118,12 @@ func MakeHandler(svc manager.Service) http.Handler {
opts...,
))
r.GetFunc("/version", mainflux.Version())
r.Handle("/metrics", promhttp.Handler())
return r
}
func decodeInfo(_ context.Context, r *http.Request) (interface{}, error) {
req := infoReq{}
return req, nil
}
func decodeCredentials(_ context.Context, r *http.Request) (interface{}, error) {
var user manager.User
if err := json.NewDecoder(r.Body).Decode(&user); err != nil {

View File

@ -1,13 +0,0 @@
package manager
const Version = "1.0.0"
type Info struct {
Version string
}
func getInfo() (Info, error) {
info := Info{Version: Version}
return info, nil
}

View File

@ -22,14 +22,6 @@ func NewService(users UserRepository, clients ClientRepository, channels Channel
}
}
func (ms *managerService) Info() (Info, error) {
info, err := getInfo()
if err != nil {
return Info{}, err
}
return info, nil
}
func (ms *managerService) Register(user User) error {
if err := user.validate(); err != nil {
return err

View File

@ -24,9 +24,6 @@ var (
// Service specifies an API that must be fullfiled by the domain service
// implementation, and all of its decorators (e.g. logging & metrics).
type Service interface {
// Version
Info() (Info, error)
// Register creates new user account. In case of the failed registration, a
// non-nil error value is returned.
Register(User) error

25
version.go Normal file
View File

@ -0,0 +1,25 @@
// Package mainflux acts as an umbrella package containing multiple different
// microservices / deliverables. It provides the top-level platform versioning.
package mainflux
import (
"encoding/json"
"net/http"
)
const version string = "1.0.0"
type response struct {
Version string
}
// Version exposes an HTTP handler for retrieving service version.
func Version() http.HandlerFunc {
return http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
res := response{Version: version}
data, _ := json.Marshal(res)
rw.Write(data)
})
}