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


Golang middleware.Context类代码示例

本文整理汇总了Golang中github.com/ChihChaoChang/worldping-api/pkg/middleware.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: V1GetOrgQuotas

func V1GetOrgQuotas(c *middleware.Context) {
	var quotas []m.OrgQuotaDTO
	var err error
	if setting.Quota.Enabled {
		quotas, err = sqlstore.GetOrgQuotas(c.OrgId)
		if err != nil {
			handleError(c, err)
			return
		}
	} else {
		quotas = []m.OrgQuotaDTO{
			{
				OrgId:  c.OrgId,
				Target: "endpoint",
				Limit:  -1,
				Used:   -10,
			},
			{
				OrgId:  c.OrgId,
				Target: "probe",
				Limit:  -1,
				Used:   -10,
			},
		}
	}
	c.JSON(200, quotas)
}
开发者ID:ChihChaoChang,项目名称:worldping-api,代码行数:27,代码来源:quota.go

示例2: V1DeleteMonitor

func V1DeleteMonitor(c *middleware.Context) {
	id := c.ParamsInt64(":id")

	check, err := sqlstore.GetCheckById(c.OrgId, id)
	if err != nil {
		handleError(c, err)
		return
	}

	// get the endpoint that the check belongs too.
	endpoint, err := sqlstore.GetEndpointById(c.OrgId, check.EndpointId)
	if err != nil {
		handleError(c, err)
		return
	}

	// now update the endpoint and remove the check.
	newChecks := make([]m.Check, 0)
	for _, ch := range endpoint.Checks {
		if ch.Id != id {
			newChecks = append(newChecks, ch)
		}
	}
	endpoint.Checks = newChecks
	err = sqlstore.UpdateEndpoint(endpoint)
	if err != nil {
		handleError(c, err)
		return
	}
	c.JSON(200, "monitor deleted")
}
开发者ID:ChihChaoChang,项目名称:worldping-api,代码行数:31,代码来源:monitor.go

示例3: GetOrgQuotas

func GetOrgQuotas(c *middleware.Context) *rbody.ApiResponse {
	var quotas []m.OrgQuotaDTO
	var err error
	org := c.ParamsInt64("orgId")
	if setting.Quota.Enabled {
		quotas, err = sqlstore.GetOrgQuotas(org)
		if err != nil {
			return rbody.ErrResp(500, err)
		}
	} else {
		quotas = []m.OrgQuotaDTO{
			{
				OrgId:  org,
				Target: "endpoint",
				Limit:  -1,
				Used:   -1,
			},
			{
				OrgId:  org,
				Target: "probe",
				Limit:  -1,
				Used:   -1,
			},
		}
	}

	return rbody.OkResp("quotas", quotas)
}
开发者ID:ChihChaoChang,项目名称:worldping-api,代码行数:28,代码来源:quota.go

示例4: V1GetCollectors

func V1GetCollectors(c *middleware.Context, query m.GetProbesQuery) {
	query.OrgId = c.OrgId
	probes, err := sqlstore.GetProbes(&query)
	if err != nil {
		handleError(c, err)
		return
	}
	c.JSON(200, probes)
	return
}
开发者ID:ChihChaoChang,项目名称:worldping-api,代码行数:10,代码来源:collector.go

示例5: V1DeleteCollector

func V1DeleteCollector(c *middleware.Context) {
	id := c.ParamsInt64(":id")

	err := sqlstore.DeleteProbe(id, c.OrgId)
	if err != nil {
		handleError(c, err)
		return
	}

	c.JSON(200, "collector deleted")
	return
}
开发者ID:ChihChaoChang,项目名称:worldping-api,代码行数:12,代码来源:collector.go

示例6: V1GetCollectorById

func V1GetCollectorById(c *middleware.Context) {
	id := c.ParamsInt64(":id")

	probe, err := sqlstore.GetProbeById(id, c.OrgId)
	if err != nil {
		handleError(c, err)
		return
	}

	c.JSON(200, probe)
	return
}
开发者ID:ChihChaoChang,项目名称:worldping-api,代码行数:12,代码来源:collector.go

示例7: V1GetMonitors

func V1GetMonitors(c *middleware.Context, query m.GetMonitorsQuery) {
	endpoint, err := sqlstore.GetEndpointById(c.OrgId, query.EndpointId)
	if err != nil {
		handleError(c, err)
		return
	}
	if endpoint == nil {
		c.JSON(200, []m.MonitorDTO{})
	}

	monitors := make([]m.MonitorDTO, len(endpoint.Checks))
	for i, check := range endpoint.Checks {
		monitors[i] = m.MonitorDTOFromCheck(check, endpoint.Slug)
		if check.Enabled {
			probeList, err := sqlstore.GetProbesForCheck(&check)
			if err != nil {
				handleError(c, err)
				return
			}
			monitors[i].Collectors = probeList
		}
	}
	c.JSON(200, monitors)
}
开发者ID:ChihChaoChang,项目名称:worldping-api,代码行数:24,代码来源:monitor.go

示例8: V1GetCollectorLocations

func V1GetCollectorLocations(c *middleware.Context) {
	query := m.GetProbesQuery{
		OrgId: c.OrgId,
	}

	probes, err := sqlstore.GetProbes(&query)
	if err != nil {
		handleError(c, err)
		return
	}

	locations := make([]m.ProbeLocationDTO, len(probes))
	for i, c := range probes {
		locations[i] = m.ProbeLocationDTO{
			Key:       c.Slug,
			Latitude:  c.Latitude,
			Longitude: c.Longitude,
			Name:      c.Name,
		}
	}

	c.JSON(200, locations)
	return
}
开发者ID:ChihChaoChang,项目名称:worldping-api,代码行数:24,代码来源:collector.go

示例9: V1AddCollector

func V1AddCollector(c *middleware.Context, probe m.ProbeDTO) {
	probe.OrgId = c.OrgId
	if probe.Id != 0 {
		c.JSON(400, "Id already set. Try update instead of create.")
		return
	}
	if probe.Name == "" {
		c.JSON(400, "Collector Name not set.")
		return
	}

	if err := sqlstore.AddProbe(&probe); err != nil {
		handleError(c, err)
		return
	}

	c.JSON(200, probe)
	return
}
开发者ID:ChihChaoChang,项目名称:worldping-api,代码行数:19,代码来源:collector.go

示例10: UpdateOrgQuota

func UpdateOrgQuota(c *middleware.Context) *rbody.ApiResponse {
	orgId := c.ParamsInt64(":orgId")
	target := c.Params(":target")
	limit := c.ParamsInt64(":limit")

	if _, ok := setting.Quota.Org.ToMap()[target]; !ok {
		return rbody.NotFound
	}

	quota := m.OrgQuotaDTO{
		OrgId:  orgId,
		Target: target,
		Limit:  limit,
	}
	err := sqlstore.UpdateOrgQuota(&quota)
	if err != nil {
		return rbody.ErrResp(500, err)
	}
	return rbody.OkResp("quota", quota)
}
开发者ID:ChihChaoChang,项目名称:worldping-api,代码行数:20,代码来源:quota.go

示例11: V1UpdateCollector

func V1UpdateCollector(c *middleware.Context, probe m.ProbeDTO) {
	probe.OrgId = c.OrgId
	if probe.Name == "" {
		c.JSON(400, "Collector Name not set.")
		return
	}

	if probe.Public {
		if !c.IsAdmin {
			c.JSON(400, "Only admins can make public collectors")
			return
		}
	}

	if err := sqlstore.UpdateProbe(&probe); err != nil {
		handleError(c, err)
		return
	}

	c.JSON(200, probe)
	return
}
开发者ID:ChihChaoChang,项目名称:worldping-api,代码行数:22,代码来源:collector.go

示例12: V1AddMonitor

func V1AddMonitor(c *middleware.Context, cmd m.AddMonitorCommand) {
	cmd.OrgId = c.OrgId
	if cmd.EndpointId == 0 {
		c.JSON(400, "EndpointId not set.")
		return
	}
	if cmd.MonitorTypeId == 0 {
		c.JSON(400, "MonitorTypeId not set.")
		return
	}
	if cmd.MonitorTypeId > 4 {
		c.JSON(400, "Invlaid MonitorTypeId.")
		return
	}
	if cmd.Frequency == 0 {
		c.JSON(400, "Frequency not set.")
		return
	}

	// get the endpoint that the check belongs too.
	endpoint, err := sqlstore.GetEndpointById(c.OrgId, cmd.EndpointId)
	if err != nil {
		handleError(c, err)
		return
	}
	if endpoint == nil {
		c.JSON(400, "endpoint does not exist.")
		return
	}

	for _, check := range endpoint.Checks {
		if checkTypeToId(check.Type) == cmd.MonitorTypeId {
			c.JSON(400, fmt.Sprintf("Endpoint already has a %s check.", check.Type))
			return
		}
	}

	route := &m.CheckRoute{}
	if len(cmd.CollectorTags) > 0 {
		route.Type = m.RouteByTags
		route.Config = map[string]interface{}{
			"tags": cmd.CollectorTags,
		}
	} else {
		route.Type = m.RouteByIds
		route.Config = map[string]interface{}{
			"ids": cmd.CollectorIds,
		}
	}

	check := m.Check{
		OrgId:          cmd.OrgId,
		EndpointId:     cmd.EndpointId,
		Type:           m.MonitorTypeToCheckTypeMap[cmd.MonitorTypeId-1],
		Frequency:      cmd.Frequency,
		Enabled:        cmd.Enabled,
		HealthSettings: cmd.HealthSettings,
		Created:        time.Now(),
		Updated:        time.Now(),
		Route:          route,
		Settings:       m.MonitorSettingsDTO(cmd.Settings).ToV2Setting(m.MonitorTypeToCheckTypeMap[cmd.MonitorTypeId-1]),
	}
	err = sqlstore.ValidateCheckRoute(&check)
	if err != nil {
		handleError(c, err)
		return
	}
	endpoint.Checks = append(endpoint.Checks, check)

	//Update endpoint
	err = sqlstore.UpdateEndpoint(endpoint)
	if err != nil {
		handleError(c, err)
		return
	}

	var monitor m.MonitorDTO
	for _, check := range endpoint.Checks {

		if check.Type == m.MonitorTypeToCheckTypeMap[cmd.MonitorTypeId-1] {
			monitor = m.MonitorDTOFromCheck(check, endpoint.Slug)
			if check.Enabled {
				probeList, err := sqlstore.GetProbesForCheck(&check)
				if err != nil {
					handleError(c, err)
					return
				}

				monitor.Collectors = probeList
			}
			break
		}
	}

	c.JSON(200, monitor)
	return
}
开发者ID:ChihChaoChang,项目名称:worldping-api,代码行数:97,代码来源:monitor.go

示例13: V1GetMonitorTypes

func V1GetMonitorTypes(c *middleware.Context) {
	c.JSON(200, m.MonitorTypes)
}
开发者ID:ChihChaoChang,项目名称:worldping-api,代码行数:3,代码来源:monitor.go

示例14: V1UpdateMonitor

func V1UpdateMonitor(c *middleware.Context, cmd m.UpdateMonitorCommand) {
	cmd.OrgId = c.OrgId
	if cmd.EndpointId == 0 {
		c.JSON(400, "EndpointId not set.")
		return
	}
	if cmd.MonitorTypeId == 0 {
		c.JSON(400, "MonitorTypeId not set.")
		return
	}
	if cmd.MonitorTypeId > 4 {
		c.JSON(400, "Invlaid MonitorTypeId.")
		return
	}
	if cmd.Frequency == 0 {
		c.JSON(400, "Frequency not set.")
		return
	}

	// get the endpoint that the check belongs too.
	endpoint, err := sqlstore.GetEndpointById(c.OrgId, cmd.EndpointId)
	if err != nil {
		handleError(c, err)
		return
	}
	if endpoint == nil {
		c.JSON(400, "endpoint does not exist.")
		return
	}
	route := &m.CheckRoute{}
	if len(cmd.CollectorTags) > 0 {
		route.Type = m.RouteByTags
		route.Config = map[string]interface{}{
			"tags": cmd.CollectorTags,
		}
	} else {
		route.Type = m.RouteByIds
		route.Config = map[string]interface{}{
			"ids": cmd.CollectorIds,
		}
	}
	checkPos := 0
	found := false
	for pos, check := range endpoint.Checks {
		if check.Id == cmd.Id {
			checkPos = pos
			found = true
			log.Debug("updating check %d of endpoint %s", check.Id, endpoint.Slug)
			if check.Type != m.MonitorTypeToCheckTypeMap[cmd.MonitorTypeId-1] {
				c.JSON(400, "monitor Type cant be changed.")
				return
			}
			break
		}
	}
	if !found {
		c.JSON(400, "check does not exist in endpoint.")
		return
	}
	endpoint.Checks[checkPos].Frequency = cmd.Frequency
	endpoint.Checks[checkPos].Enabled = cmd.Enabled
	endpoint.Checks[checkPos].HealthSettings = cmd.HealthSettings
	endpoint.Checks[checkPos].Updated = time.Now()
	endpoint.Checks[checkPos].Route = route
	endpoint.Checks[checkPos].Settings = m.MonitorSettingsDTO(cmd.Settings).ToV2Setting(m.MonitorTypeToCheckTypeMap[cmd.MonitorTypeId-1])

	err = sqlstore.ValidateCheckRoute(&endpoint.Checks[checkPos])
	if err != nil {
		handleError(c, err)
		return
	}

	err = sqlstore.UpdateEndpoint(endpoint)
	if err != nil {
		handleError(c, err)
		return
	}

	c.JSON(200, "Monitor updated")
}
开发者ID:ChihChaoChang,项目名称:worldping-api,代码行数:80,代码来源:monitor.go


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