File size: 1,173 Bytes
13555f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package api

import (
	"encoding/json"
	"net/http"

	"github.com/gorilla/mux"
)

func (a *API) registerSystemRoutes(r *mux.Router) {
	// System APIs
	r.HandleFunc("/hello", a.handleHello).Methods("GET")
	r.HandleFunc("/ping", a.handlePing).Methods("GET")
}

func (a *API) handleHello(w http.ResponseWriter, r *http.Request) {
	// swagger:operation GET /hello hello
	//
	// Responds with `Hello` if the web service is running.
	//
	// ---
	// produces:
	// - text/plain
	// responses:
	//   '200':
	//     description: success
	stringResponse(w, "Hello")
}

func (a *API) handlePing(w http.ResponseWriter, r *http.Request) {
	// swagger:operation GET /ping ping
	//
	// Responds with server metadata if the web service is running.
	//
	// ---
	// produces:
	// - application/json
	// responses:
	//   '200':
	//     description: success
	serverMetadata := a.app.GetServerMetadata()

	if a.singleUserToken != "" {
		serverMetadata.SKU = "personal_desktop"
	}

	if serverMetadata.Edition == "plugin" {
		serverMetadata.SKU = "suite"
	}

	bytes, err := json.Marshal(serverMetadata)
	if err != nil {
		a.errorResponse(w, r, err)
	}

	jsonStringResponse(w, 200, string(bytes))
}