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


Golang models.Org類代碼示例

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


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

示例1: getOrgIdForNewUser

func getOrgIdForNewUser(userEmail string, sess *session) (int64, error) {
	var org m.Org

	if setting.AutoAssignOrg {
		// right now auto assign to org with id 1
		has, err := sess.Where("id=?", 1).Get(&org)
		if err != nil {
			return 0, err
		}
		if has {
			return org.Id, nil
		} else {
			org.Name = "Main Org."
			org.Id = 1
		}
	} else {
		org.Name = userEmail
	}

	org.Created = time.Now()
	org.Updated = time.Now()

	if _, err := sess.Insert(&org); err != nil {
		return 0, err
	}

	sess.publishAfterCommit(&events.OrgCreated{
		Timestamp: org.Created,
		Id:        org.Id,
		Name:      org.Name,
	})

	return org.Id, nil
}
開發者ID:nicrioux,項目名稱:grafana,代碼行數:34,代碼來源:user.go

示例2: getOrgIdForNewUser

func getOrgIdForNewUser(cmd *m.CreateUserCommand, sess *session) (int64, error) {
	if cmd.SkipOrgSetup {
		return -1, nil
	}

	var org m.Org

	if setting.AutoAssignOrg {
		// right now auto assign to org with id 1
		has, err := sess.Where("id=?", 1).Get(&org)
		if err != nil {
			return 0, err
		}
		if has {
			return org.Id, nil
		} else {
			org.Name = "Main Org."
			org.Id = 1
		}
	} else {
		org.Name = cmd.OrgName
		if len(org.Name) == 0 {
			org.Name = util.StringsFallback2(cmd.Email, cmd.Login)
		}
	}

	org.Created = time.Now()
	org.Updated = time.Now()

	if _, err := sess.Insert(&org); err != nil {
		return 0, err
	}

	sess.publishAfterCommit(&events.OrgCreated{
		Timestamp: org.Created,
		Id:        org.Id,
		Name:      org.Name,
	})

	return org.Id, nil
}
開發者ID:wk66,項目名稱:grafana,代碼行數:41,代碼來源:user.go


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