forked from akvorado/akvorado
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.go
43 lines (37 loc) · 972 Bytes
/
http.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
43
// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
package orchestrator
import (
"net/http"
"strconv"
"github.com/gin-gonic/gin"
)
func (c *Component) configurationHandlerFunc(gc *gin.Context) {
service := gc.Param("service")
indexStr := gc.Param("index")
index, err := strconv.Atoi(indexStr)
if indexStr != "" && err != nil {
gc.JSON(http.StatusNotFound, gin.H{"message": "Invalid configuration index."})
return
}
c.serviceLock.Lock()
var configuration interface{}
serviceConfigurations, ok := c.serviceConfigurations[ServiceType(service)]
if ok {
l := len(serviceConfigurations)
switch {
case l == 0:
ok = false
case index < l:
configuration = serviceConfigurations[index]
default:
configuration = serviceConfigurations[0]
}
}
c.serviceLock.Unlock()
if !ok {
gc.JSON(http.StatusNotFound, gin.H{"message": "Configuration not found."})
return
}
gc.YAML(http.StatusOK, configuration)
}