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


Golang Context.JsonOK方法代码示例

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


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

示例1: AdminUpdateUserPassword

func AdminUpdateUserPassword(c *middleware.Context, form dtos.AdminUpdateUserPasswordForm) {
	userId := c.ParamsInt64(":id")

	if len(form.Password) < 4 {
		c.JsonApiErr(400, "New password too short", nil)
		return
	}

	userQuery := m.GetUserByIdQuery{Id: userId}

	if err := bus.Dispatch(&userQuery); err != nil {
		c.JsonApiErr(500, "Could not read user from database", err)
		return
	}

	passwordHashed := util.EncodePassword(form.Password, userQuery.Result.Salt)

	cmd := m.ChangeUserPasswordCommand{
		UserId:      userId,
		NewPassword: passwordHashed,
	}

	if err := bus.Dispatch(&cmd); err != nil {
		c.JsonApiErr(500, "Failed to update user password", err)
		return
	}

	c.JsonOK("User password updated")
}
开发者ID:chengweiv5,项目名称:grafana,代码行数:29,代码来源:admin_users.go

示例2: AdminCreateUser

func AdminCreateUser(c *middleware.Context, form dtos.AdminCreateUserForm) {
	cmd := m.CreateUserCommand{
		Login:    form.Login,
		Email:    form.Email,
		Password: form.Password,
		Name:     form.Name,
	}

	if len(cmd.Login) == 0 {
		cmd.Login = cmd.Email
		if len(cmd.Login) == 0 {
			c.JsonApiErr(400, "Validation error, need specify either username or email", nil)
			return
		}
	}

	if len(cmd.Password) < 4 {
		c.JsonApiErr(400, "Password is missing or too short", nil)
		return
	}

	if err := bus.Dispatch(&cmd); err != nil {
		c.JsonApiErr(500, "failed to create user", err)
		return
	}

	metrics.M_Api_Admin_User_Create.Inc(1)

	c.JsonOK("User created")
}
开发者ID:chengweiv5,项目名称:grafana,代码行数:30,代码来源:admin_users.go

示例3: LoginApiPing

func LoginApiPing(c *middleware.Context) {
	if !tryLoginUsingRememberCookie(c) {
		c.JsonApiErr(401, "Unauthorized", nil)
		return
	}

	c.JsonOK("Logged in")
}
开发者ID:replay,项目名称:grafana,代码行数:8,代码来源:login.go

示例4: UpdateDataSource

func UpdateDataSource(c *middleware.Context, cmd m.UpdateDataSourceCommand) {
	cmd.OrgId = c.OrgId
	cmd.Id = c.ParamsInt64(":id")

	err := bus.Dispatch(&cmd)
	if err != nil {
		c.JsonApiErr(500, "Failed to update datasource", err)
		return
	}

	c.JsonOK("Datasource updated")
}
开发者ID:nickrobinson,项目名称:grafana,代码行数:12,代码来源:datasources.go

示例5: AdminDeleteUser

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

	cmd := m.DeleteUserCommand{UserId: userId}

	if err := bus.Dispatch(&cmd); err != nil {
		c.JsonApiErr(500, "Failed to delete user", err)
		return
	}

	c.JsonOK("User deleted")
}
开发者ID:chengweiv5,项目名称:grafana,代码行数:12,代码来源:admin_users.go

示例6: DeleteAlert

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

	cmd := &m.DeleteAlertCommand{Id: id, OrgId: c.OrgId}

	err := bus.Dispatch(cmd)
	if err != nil {
		c.JsonApiErr(500, "Failed to delete alert", err)
		return
	}

	c.JsonOK("Alert deleted")
}
开发者ID:reduxdj,项目名称:grafana,代码行数:13,代码来源:alert.go

示例7: LoginApiPing

func LoginApiPing(c *middleware.Context) {
	if !tryLoginUsingRememberCookie(c) {
		initialized, err := netcrunch.CheckInitializationSuccess()

		if (err == nil) && (!initialized) {
			c.JsonApiErr(401, "Default credentials for fresh installation: User: admin Password: admin", nil)
		} else {
			c.JsonApiErr(401, "Unauthorized", nil)
		}
		return
	}

	c.JsonOK("Logged in")
}
开发者ID:adremsoft,项目名称:NetCrunch-grafana,代码行数:14,代码来源:login.go

示例8: AdminUpdateUserPermissions

func AdminUpdateUserPermissions(c *middleware.Context, form dtos.AdminUpdateUserPermissionsForm) {
	userId := c.ParamsInt64(":id")

	cmd := m.UpdateUserPermissionsCommand{
		UserId:         userId,
		IsGrafanaAdmin: form.IsGrafanaAdmin,
	}

	if err := bus.Dispatch(&cmd); err != nil {
		c.JsonApiErr(500, "Failed to update user permissions", err)
		return
	}

	c.JsonOK("User permissions updated")
}
开发者ID:chengweiv5,项目名称:grafana,代码行数:15,代码来源:admin_users.go

示例9: DeleteDataSource

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

	if id <= 0 {
		c.JsonApiErr(400, "Missing valid datasource id", nil)
		return
	}

	cmd := &m.DeleteDataSourceCommand{Id: id, OrgId: c.OrgId}

	err := bus.Dispatch(cmd)
	if err != nil {
		c.JsonApiErr(500, "Failed to delete datasource", err)
		return
	}

	c.JsonOK("Data source deleted")
}
开发者ID:nickrobinson,项目名称:grafana,代码行数:18,代码来源:datasources.go

示例10: PushToStream

func (lc *LiveConn) PushToStream(c *middleware.Context, message dtos.StreamMessage) {
	h.streamChannel <- &message
	c.JsonOK("Message recevived")
}
开发者ID:Xetius,项目名称:grafana,代码行数:4,代码来源:live.go


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