當前位置: 首頁>>代碼示例>>Golang>>正文


Golang models.UpdatePluginSettingCmd類代碼示例

本文整理匯總了Golang中github.com/grafana/grafana/pkg/models.UpdatePluginSettingCmd的典型用法代碼示例。如果您正苦於以下問題:Golang UpdatePluginSettingCmd類的具體用法?Golang UpdatePluginSettingCmd怎麽用?Golang UpdatePluginSettingCmd使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了UpdatePluginSettingCmd類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: UpdatePluginSetting

func UpdatePluginSetting(cmd *m.UpdatePluginSettingCmd) error {
	return inTransaction2(func(sess *session) error {
		var pluginSetting m.PluginSetting

		exists, err := sess.Where("org_id=? and plugin_id=?", cmd.OrgId, cmd.PluginId).Get(&pluginSetting)
		sess.UseBool("enabled")
		sess.UseBool("pinned")
		if !exists {
			pluginSetting = m.PluginSetting{
				PluginId:       cmd.PluginId,
				OrgId:          cmd.OrgId,
				Enabled:        cmd.Enabled,
				Pinned:         cmd.Pinned,
				JsonData:       cmd.JsonData,
				SecureJsonData: cmd.GetEncryptedJsonData(),
				Created:        time.Now(),
				Updated:        time.Now(),
			}
			_, err = sess.Insert(&pluginSetting)
			return err
		} else {
			for key, data := range cmd.SecureJsonData {
				pluginSetting.SecureJsonData[key] = util.Encrypt([]byte(data), setting.SecretKey)
			}
			pluginSetting.Updated = time.Now()
			pluginSetting.Enabled = cmd.Enabled
			pluginSetting.JsonData = cmd.JsonData
			pluginSetting.Pinned = cmd.Pinned
			_, err = sess.Id(pluginSetting.Id).Update(&pluginSetting)
			return err
		}
	})
}
開發者ID:chancez,項目名稱:grafana,代碼行數:33,代碼來源:plugin_setting.go

示例2: UpdatePluginSetting

func UpdatePluginSetting(cmd *m.UpdatePluginSettingCmd) error {
	return inTransaction2(func(sess *session) error {
		var pluginSetting m.PluginSetting

		exists, err := sess.Where("org_id=? and plugin_id=?", cmd.OrgId, cmd.PluginId).Get(&pluginSetting)
		sess.UseBool("enabled")
		sess.UseBool("pinned")
		if !exists {
			pluginSetting = m.PluginSetting{
				PluginId:       cmd.PluginId,
				OrgId:          cmd.OrgId,
				Enabled:        cmd.Enabled,
				Pinned:         cmd.Pinned,
				JsonData:       cmd.JsonData,
				PluginVersion:  cmd.PluginVersion,
				SecureJsonData: cmd.GetEncryptedJsonData(),
				Created:        time.Now(),
				Updated:        time.Now(),
			}

			// add state change event on commit success
			sess.events = append(sess.events, &m.PluginStateChangedEvent{
				PluginId: cmd.PluginId,
				OrgId:    cmd.OrgId,
				Enabled:  cmd.Enabled,
			})

			_, err = sess.Insert(&pluginSetting)
			return err
		} else {
			for key, data := range cmd.SecureJsonData {
				pluginSetting.SecureJsonData[key] = util.Encrypt([]byte(data), setting.SecretKey)
			}

			// add state change event on commit success
			if pluginSetting.Enabled != cmd.Enabled {
				sess.events = append(sess.events, &m.PluginStateChangedEvent{
					PluginId: cmd.PluginId,
					OrgId:    cmd.OrgId,
					Enabled:  cmd.Enabled,
				})
			}

			pluginSetting.Updated = time.Now()
			pluginSetting.Enabled = cmd.Enabled
			pluginSetting.JsonData = cmd.JsonData
			pluginSetting.Pinned = cmd.Pinned
			pluginSetting.PluginVersion = cmd.PluginVersion

			_, err = sess.Id(pluginSetting.Id).Update(&pluginSetting)
			return err
		}
	})
}
開發者ID:Robin7Ma,項目名稱:grafana,代碼行數:54,代碼來源:plugin_setting.go

示例3: UpdatePluginSetting

func UpdatePluginSetting(c *middleware.Context, cmd m.UpdatePluginSettingCmd) Response {
	pluginId := c.Params(":pluginId")

	cmd.OrgId = c.OrgId
	cmd.PluginId = pluginId

	if _, ok := plugins.Apps[cmd.PluginId]; !ok {
		return ApiError(404, "Plugin not installed.", nil)
	}

	if err := bus.Dispatch(&cmd); err != nil {
		return ApiError(500, "Failed to update plugin setting", err)
	}

	return ApiSuccess("Plugin settings updated")
}
開發者ID:Xetius,項目名稱:grafana,代碼行數:16,代碼來源:plugins.go


注:本文中的github.com/grafana/grafana/pkg/models.UpdatePluginSettingCmd類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。