本文整理匯總了Golang中github.com/grafana/grafana/pkg/models.AddDataSourceCommand類的典型用法代碼示例。如果您正苦於以下問題:Golang AddDataSourceCommand類的具體用法?Golang AddDataSourceCommand怎麽用?Golang AddDataSourceCommand使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了AddDataSourceCommand類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AddDataSource
func AddDataSource(cmd *m.AddDataSourceCommand) error {
return inTransaction(func(sess *xorm.Session) error {
ds := &m.DataSource{
OrgId: cmd.OrgId,
Name: cmd.Name,
Type: cmd.Type,
Access: cmd.Access,
Url: cmd.Url,
User: cmd.User,
Password: cmd.Password,
Database: cmd.Database,
IsDefault: cmd.IsDefault,
BasicAuth: cmd.BasicAuth,
BasicAuthUser: cmd.BasicAuthUser,
BasicAuthPassword: cmd.BasicAuthPassword,
WithCredentials: cmd.WithCredentials,
JsonData: cmd.JsonData,
Created: time.Now(),
Updated: time.Now(),
}
if _, err := sess.Insert(ds); err != nil {
return err
}
if err := updateIsDefaultFlag(ds, sess); err != nil {
return err
}
cmd.Result = ds
return nil
})
}
示例2: AddDataSource
func AddDataSource(c *middleware.Context, cmd m.AddDataSourceCommand) {
cmd.OrgId = c.OrgId
if err := bus.Dispatch(&cmd); err != nil {
c.JsonApiErr(500, "Failed to add datasource", err)
return
}
c.JSON(200, util.DynMap{"message": "Datasource added", "id": cmd.Result.Id})
}