forked from SpectoLabs/hoverfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hoverfly_version_handler.go
42 lines (33 loc) · 1.05 KB
/
hoverfly_version_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package v2
import (
"encoding/json"
"net/http"
"github.com/SpectoLabs/hoverfly/core/handlers"
"github.com/codegangsta/negroni"
"github.com/go-zoo/bone"
)
type HoverflyVersion interface {
GetVersion() string
}
type HoverflyVersionHandler struct {
Hoverfly HoverflyVersion
}
func (this *HoverflyVersionHandler) RegisterRoutes(mux *bone.Mux, am *handlers.AuthHandler) {
mux.Get("/api/v2/hoverfly/version", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(this.Get),
))
mux.Options("/api/v2/hoverfly/version", negroni.New(
negroni.HandlerFunc(this.Options),
))
}
func (this *HoverflyVersionHandler) Get(w http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
var versionView VersionView
versionView.Version = this.Hoverfly.GetVersion()
bytes, _ := json.Marshal(versionView)
handlers.WriteResponse(w, bytes)
}
func (this *HoverflyVersionHandler) Options(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
w.Header().Add("Allow", "OPTIONS, GET")
handlers.WriteResponse(w, []byte(""))
}