Пример #1
0
func GetContainers(
    c context.Context,
    w http.ResponseWriter,
    r *http.Request) (int, map[string]interface{}) {
    planet := c.GetQueryParam("planet", "")

    var status int
    var res map[string]interface{}
    
    if planet == "" {
        status = http.StatusBadRequest
        res := map[string]interface{} { "error": "planet is empty." }
        return status, res
    }

    containers, err := c.InfluxDB.QueryContainers(planet)
    if err != nil {
        status = http.StatusBadRequest
        res = map[string]interface{} { "error": err.Error() }
        return status, res
    }

    status = http.StatusOK
    res = map[string]interface{} {
        "data": containers,
    }

    return status, res
}
Пример #2
0
func GetMetrics(
	c context.Context,
	w http.ResponseWriter,
	r *http.Request) (int, map[string]interface{}) {
	t := c.GetQueryParam("type", "")
	planet := c.GetQueryParam("planet", "")
	container := c.GetQueryParam("container", "")

	var res map[string]interface{}

	if types[t] == false {
		err := fmt.Sprintf("%s type is not supported.", t)
		res = map[string]interface{}{"error": err}
		return http.StatusBadRequest, res
	}

	if planet == "" {
		err := fmt.Sprintf("planet is empty.")
		res = map[string]interface{}{"error": err}
		return http.StatusBadRequest, res
	}

	var metrics interface{}
	var err error

	if container == "" {
		metrics, err = c.InfluxDB.QueryPlanetMetrics(planet, t)
	} else {
		metrics, err = c.InfluxDB.QueryContainerMetrics(planet, container, t)
	}

	if err != nil {
		res := map[string]interface{}{"error": err.Error()}
		return http.StatusInternalServerError, res
	}

	res = map[string]interface{}{
		"data": metrics,
	}

	return http.StatusOK, res
}