当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.QueryInt64方法代码示例

本文整理汇总了Golang中github.com/grafana/grafana/pkg/middleware.Context.QueryInt64方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.QueryInt64方法的具体用法?Golang Context.QueryInt64怎么用?Golang Context.QueryInt64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/grafana/grafana/pkg/middleware.Context的用法示例。


在下文中一共展示了Context.QueryInt64方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getAlertIdForRequest

func getAlertIdForRequest(c *middleware.Context) (int64, error) {
	alertId := c.QueryInt64("alertId")
	panelId := c.QueryInt64("panelId")
	dashboardId := c.QueryInt64("dashboardId")

	if alertId == 0 && dashboardId == 0 && panelId == 0 {
		return 0, fmt.Errorf("Missing alertId or dashboardId and panelId")
	}

	if alertId == 0 {
		//fetch alertId
		query := models.GetAlertsQuery{
			OrgId:       c.OrgId,
			DashboardId: dashboardId,
			PanelId:     panelId,
		}

		if err := bus.Dispatch(&query); err != nil {
			return 0, err
		}

		if len(query.Result) != 1 {
			return 0, fmt.Errorf("PanelId is not unique on dashboard")
		}

		alertId = query.Result[0].Id
	}

	return alertId, nil
}
开发者ID:roman-vynar,项目名称:grafana,代码行数:30,代码来源:alerting.go

示例2: GetAlertStatesForDashboard

func GetAlertStatesForDashboard(c *middleware.Context) Response {
	dashboardId := c.QueryInt64("dashboardId")

	if dashboardId == 0 {
		return ApiError(400, "Missing query parameter dashboardId", nil)
	}

	query := models.GetAlertStatesForDashboardQuery{
		OrgId:       c.OrgId,
		DashboardId: c.QueryInt64("dashboardId"),
	}

	if err := bus.Dispatch(&query); err != nil {
		return ApiError(500, "Failed to fetch alert states", err)
	}

	return Json(200, query.Result)
}
开发者ID:alexanderzobnin,项目名称:grafana,代码行数:18,代码来源:alerting.go

示例3: GetTestMetrics

func GetTestMetrics(c *middleware.Context) {
	from := c.QueryInt64("from")
	to := c.QueryInt64("to")
	maxDataPoints := c.QueryInt64("maxDataPoints")
	stepInSeconds := (to - from) / maxDataPoints

	result := dtos.MetricQueryResultDto{}
	result.Data = make([]dtos.MetricQueryResultDataDto, 1)

	for seriesIndex := range result.Data {
		points := make([][2]float64, maxDataPoints)
		walker := rand.Float64() * 100
		time := from

		for i := range points {
			points[i][0] = walker
			points[i][1] = float64(time)
			walker += rand.Float64() - 0.5
			time += stepInSeconds
		}

		result.Data[seriesIndex].Target = "test-series-" + strconv.Itoa(seriesIndex)
		result.Data[seriesIndex].DataPoints = points
	}

	c.JSON(200, &result)
}
开发者ID:mbrukman,项目名称:grafana,代码行数:27,代码来源:metrics.go

示例4: GetAlerts

// GET /api/alerts
func GetAlerts(c *middleware.Context) Response {
	query := models.GetAlertsQuery{
		OrgId:       c.OrgId,
		DashboardId: c.QueryInt64("dashboardId"),
		PanelId:     c.QueryInt64("panelId"),
		Limit:       c.QueryInt64("limit"),
	}

	states := c.QueryStrings("state")
	if len(states) > 0 {
		query.State = states
	}

	if err := bus.Dispatch(&query); err != nil {
		return ApiError(500, "List alerts failed", err)
	}

	dashboardIds := make([]int64, 0)
	alertDTOs := make([]*dtos.AlertRule, 0)
	for _, alert := range query.Result {
		dashboardIds = append(dashboardIds, alert.DashboardId)
		alertDTOs = append(alertDTOs, &dtos.AlertRule{
			Id:             alert.Id,
			DashboardId:    alert.DashboardId,
			PanelId:        alert.PanelId,
			Name:           alert.Name,
			Message:        alert.Message,
			State:          alert.State,
			EvalDate:       alert.EvalDate,
			NewStateDate:   alert.NewStateDate,
			ExecutionError: alert.ExecutionError,
		})
	}

	dashboardsQuery := models.GetDashboardsQuery{
		DashboardIds: dashboardIds,
	}

	if len(alertDTOs) > 0 {
		if err := bus.Dispatch(&dashboardsQuery); err != nil {
			return ApiError(500, "List alerts failed", err)
		}
	}

	//TODO: should be possible to speed this up with lookup table
	for _, alert := range alertDTOs {
		for _, dash := range dashboardsQuery.Result {
			if alert.DashboardId == dash.Id {
				alert.DashbboardUri = "db/" + dash.Slug
			}
		}
	}

	return Json(200, alertDTOs)
}
开发者ID:alexanderzobnin,项目名称:grafana,代码行数:56,代码来源:alerting.go

示例5: GetAnnotations

func GetAnnotations(c *middleware.Context) Response {

	query := &annotations.ItemQuery{
		From:        c.QueryInt64("from") / 1000,
		To:          c.QueryInt64("to") / 1000,
		Type:        annotations.ItemType(c.Query("type")),
		OrgId:       c.OrgId,
		AlertId:     c.QueryInt64("alertId"),
		DashboardId: c.QueryInt64("dashboardId"),
		PanelId:     c.QueryInt64("panelId"),
		Limit:       c.QueryInt64("limit"),
		NewState:    c.QueryStrings("newState"),
	}

	repo := annotations.GetRepository()

	items, err := repo.Find(query)
	if err != nil {
		return ApiError(500, "Failed to get annotations", err)
	}

	result := make([]dtos.Annotation, 0)

	for _, item := range items {
		result = append(result, dtos.Annotation{
			AlertId:   item.AlertId,
			Time:      item.Epoch * 1000,
			Data:      item.Data,
			NewState:  item.NewState,
			PrevState: item.PrevState,
			Text:      item.Text,
			Metric:    item.Metric,
			Title:     item.Title,
		})
	}

	return Json(200, result)
}
开发者ID:wk66,项目名称:grafana,代码行数:38,代码来源:annotations.go


注:本文中的github.com/grafana/grafana/pkg/middleware.Context.QueryInt64方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。