Enhance info endpoint to include gateway version

Extend the health endpoint and add gateway version information

Resolves: #733
Signed-off-by: Edward Wilde <ewilde@gmail.com>
This commit is contained in:
Edward Wilde
2018-07-02 16:42:16 +01:00
committed by Alex Ellis
parent 672a6be182
commit aca2c7fe2a
10 changed files with 209 additions and 7 deletions

View File

@ -0,0 +1,58 @@
package types
import (
"bytes"
"net/http"
)
// GatewayInfo provides information about the gateway and it's connected components
type GatewayInfo struct {
Provider *ProviderInfo `json:"provider"`
Version *VersionInfo `json:"version"`
}
// ProviderInfo provides information about the configured provider
type ProviderInfo struct {
Name string `json:"provider"`
Version *VersionInfo `json:"version"`
Orchestration string `json:"orchestration"`
}
// VersionInfo provides the commit message, sha and release version number
type VersionInfo struct {
CommitMessage string `json:"commit_message,omitempty"`
SHA string `json:"sha"`
Release string `json:"release"`
}
// StringResponseWriter captures the handlers HTTP response in a buffer
type StringResponseWriter struct {
body *bytes.Buffer
headerCode int
header http.Header
}
// NewStringResponseWriter create a new StringResponseWriter
func NewStringResponseWriter() *StringResponseWriter {
return &StringResponseWriter{body: &bytes.Buffer{}, header: make(http.Header)}
}
// Header capture the Header information
func (s StringResponseWriter) Header() http.Header {
return s.header
}
// Write captures the response data
func (s StringResponseWriter) Write(data []byte) (int, error) {
return s.body.Write(data)
}
// WriteHeader captures the status code of the response
func (s StringResponseWriter) WriteHeader(statusCode int) {
s.headerCode = statusCode
}
// Body returns the response body bytes
func (s StringResponseWriter) Body() []byte {
return s.body.Bytes()
}