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


Golang Model.NewOpenProject函數代碼示例

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


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

示例1: UpdateLike

// 更新該項目的喜歡數
// objid:被喜歡對象id;num: 喜歡數(負數表示取消喜歡)
func (self ProjectLike) UpdateLike(objid, num int) {
	// 更新喜歡數(TODO:暫時每次都更新表)
	err := model.NewOpenProject().Where("id=?", objid).Increment("likenum", num)
	if err != nil {
		logger.Errorln("更新項目喜歡數失敗:", err)
	}
}
開發者ID:allenisready,項目名稱:studygolang,代碼行數:9,代碼來源:project.go

示例2: ProjectsTotal

// 開源項目總數
func ProjectsTotal() (total int) {
	total, err := model.NewOpenProject().Count()
	if err != nil {
		logger.Errorln("project service ProjectsTotal error:", err)
	}
	return
}
開發者ID:allenisready,項目名稱:studygolang,代碼行數:8,代碼來源:project.go

示例3: UpdateProjectStatus

func UpdateProjectStatus(id, status int, username string) error {
	if status < model.StatusNew || status > model.StatusOffline {
		return errors.New("status is illegal")
	}

	logger.Infoln("UpdateProjectStatus by username:", username)

	return model.NewOpenProject().Set("status=?", status).Where("id=?", id).Update()
}
開發者ID:allenisready,項目名稱:studygolang,代碼行數:9,代碼來源:project.go

示例4: UpdateComment

// 更新該項目的評論信息
// cid:評論id;objid:被評論對象id;uid:評論者;cmttime:評論時間
func (self ProjectComment) UpdateComment(cid, objid, uid int, cmttime string) {
	id := strconv.Itoa(objid)

	// 更新評論數(TODO:暫時每次都更新表)
	err := model.NewOpenProject().Where("id="+id).Increment("cmtnum", 1)
	if err != nil {
		logger.Errorln("更新項目評論數失敗:", err)
	}
}
開發者ID:allenisready,項目名稱:studygolang,代碼行數:11,代碼來源:project.go

示例5: FindUserRecentProjects

// 獲得某個用戶最近發布的開源項目
func FindUserRecentProjects(username string) []*model.OpenProject {
	projectList, err := model.NewOpenProject().Where("username=?", username).Limit("0,5").Order("ctime DESC").FindAll()
	if err != nil {
		logger.Errorln("project service FindUserRecentProjects error:", err)
		return nil
	}

	return projectList
}
開發者ID:allenisready,項目名稱:studygolang,代碼行數:10,代碼來源:project.go

示例6: getProjectOwner

// 通過objid獲得 project 的所有者
func getProjectOwner(id int) int {
	project := model.NewOpenProject()
	err := project.Where("id=" + strconv.Itoa(id)).Find()
	if err != nil {
		logger.Errorln("project service getProjectOwner Error:", err)
		return 0
	}

	user := FindUserByUsername(project.Username)
	return user.Uid
}
開發者ID:allenisready,項目名稱:studygolang,代碼行數:12,代碼來源:project.go

示例7: FindProjectsByIds

// 獲取多個項目詳細信息
func FindProjectsByIds(ids []int) []*model.OpenProject {
	if len(ids) == 0 {
		return nil
	}
	inIds := util.Join(ids, ",")
	projects, err := model.NewOpenProject().Where("id in(" + inIds + ")").FindAll()
	if err != nil {
		logger.Errorln("project service FindProjectsByIds error:", err)
		return nil
	}
	return projects
}
開發者ID:allenisready,項目名稱:studygolang,代碼行數:13,代碼來源:project.go

示例8: ProjectUriExists

func ProjectUriExists(uri string) bool {
	project := model.NewOpenProject()
	err := project.Where("uri=?", uri).Find("id")
	if err != nil {
		return false
	}

	if project.Id > 0 {
		return true
	}

	return false
}
開發者ID:allenisready,項目名稱:studygolang,代碼行數:13,代碼來源:project.go

示例9: flush

// flush 將瀏覽數刷入數據庫中
func (this *view) flush() {
	this.locker.Lock()
	defer this.locker.Unlock()

	objid := strconv.Itoa(this.objid)
	switch this.objtype {
	case model.TYPE_TOPIC:
		model.NewTopicEx().Where("tid="+objid).Increment("view", this.num)
	case model.TYPE_ARTICLE:
		model.NewArticle().Where("id="+objid).Increment("viewnum", this.num)
	case model.TYPE_RESOURCE:
		model.NewResourceEx().Where("id="+objid).Increment("viewnum", this.num)
	case model.TYPE_PROJECT:
		model.NewOpenProject().Where("id="+objid).Increment("viewnum", this.num)
	}

	this.num = 0
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:19,代碼來源:view.go

示例10: NewProjectHandler

// 新建項目
// uri: /project/new{json:(|.json)}
func NewProjectHandler(rw http.ResponseWriter, req *http.Request) {
	vars := mux.Vars(req)
	name := req.PostFormValue("name")
	// 請求新建項目頁麵
	if name == "" || req.Method != "POST" || vars["json"] == "" {
		project := model.NewOpenProject()
		req.Form.Set(filter.CONTENT_TPL_KEY, "/template/projects/new.html")
		filter.SetData(req, map[string]interface{}{"project": project, "activeProjects": "active"})
		return
	}

	user, _ := filter.CurrentUser(req)
	err := service.PublishProject(user, req.PostForm)
	if err != nil {
		fmt.Fprint(rw, `{"ok": 0, "error":"內部服務錯誤!"}`)
		return
	}
	fmt.Fprint(rw, `{"ok": 1, "data":""}`)
}
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:21,代碼來源:project.go

示例11: FindProjects

// 獲取開源項目列表(分頁)
func FindProjects(lastId, limit string) []*model.OpenProject {
	project := model.NewOpenProject()

	query := "status IN(?,?)"
	args := []interface{}{model.StatusNew, model.StatusOnline}
	if lastId != "0" {
		query += " AND id<?"
		args = append(args, lastId)
	}

	projectList, err := project.Where(query, args...).Order("id DESC").Limit(limit).
		FindAll()
	if err != nil {
		logger.Errorln("project service FindProjects Error:", err)
		return nil
	}

	return projectList
}
開發者ID:allenisready,項目名稱:studygolang,代碼行數:20,代碼來源:project.go

示例12: FindProject

// 獲取單個項目
func FindProject(uniq string) *model.OpenProject {
	field := "id"
	_, err := strconv.Atoi(uniq)
	if err != nil {
		field = "uri"
	}

	project := model.NewOpenProject()
	err = project.Where(field+"=? AND status IN(?,?)", uniq, model.StatusNew, model.StatusOnline).Find()

	if err != nil {
		logger.Errorln("project service FindProject error:", err)
		return nil
	}

	if project.Id == 0 {
		return nil
	}

	return project
}
開發者ID:allenisready,項目名稱:studygolang,代碼行數:22,代碼來源:project.go

示例13: FindProjectByPage

// 獲取開源項目列表(分頁,後台用)
func FindProjectByPage(conds map[string]string, curPage, limit int) ([]*model.OpenProject, int) {
	conditions := make([]string, 0, len(conds))
	for k, v := range conds {
		conditions = append(conditions, k+"="+v)
	}

	project := model.NewOpenProject()

	limitStr := strconv.Itoa((curPage-1)*limit) + "," + strconv.Itoa(limit)
	projectList, err := project.Where(strings.Join(conditions, " AND ")).Order("id DESC").Limit(limitStr).
		FindAll()
	if err != nil {
		logger.Errorln("project service FindProjectByPage Error:", err)
		return nil, 0
	}

	total, err := project.Count()
	if err != nil {
		logger.Errorln("project service FindProjectByPage COUNT Error:", err)
		return nil, 0
	}

	return projectList, total
}
開發者ID:allenisready,項目名稱:studygolang,代碼行數:25,代碼來源:project.go

示例14: GenSitemap


//.........這裏部分代碼省略.........
	little = 1
	large = little + step

	// 資源
	resource := model.NewResource()
	for {
		sitemapFile := "sitemap_resource_" + strconv.Itoa(large) + ".xml"

		resources, err := resource.Where("id BETWEEN ? AND ?", little, large).FindAll("id", "mtime")
		little, large = large+1, little+step

		if err != nil {
			continue
		}

		if len(resources) == 0 {
			break
		}

		data := map[string]interface{}{
			"home":      home,
			"resources": resources,
		}

		if err = output(sitemapFile, data); err == nil {
			sitemapFiles = append(sitemapFiles, sitemapFile)
		}
	}

	little = 1
	large = little + step

	// 項目
	project := model.NewOpenProject()
	for {
		sitemapFile := "sitemap_project_" + strconv.Itoa(large) + ".xml"

		projects, err := project.Where("id BETWEEN ? AND ? AND status=?", little, large, model.StatusOnline).FindAll("id", "uri", "mtime")
		little, large = large+1, little+step

		if err != nil {
			continue
		}

		if len(projects) == 0 {
			break
		}

		data := map[string]interface{}{
			"home":     home,
			"projects": projects,
		}

		if err = output(sitemapFile, data); err == nil {
			sitemapFiles = append(sitemapFiles, sitemapFile)
		}
	}

	little = 1
	large = little + step

	// wiki
	wiki := model.NewWiki()
	for {
		sitemapFile := "sitemap_wiki_" + strconv.Itoa(large) + ".xml"
開發者ID:bluefchen,項目名稱:studygolang,代碼行數:66,代碼來源:sitemap.go

示例15: PublishProject

func PublishProject(user map[string]interface{}, form url.Values) (err error) {
	id := form.Get("id")
	isModify := id != ""

	if !isModify && ProjectUriExists(form.Get("uri")) {
		err = errors.New("uri存在")
		return
	}

	username := user["username"].(string)

	project := model.NewOpenProject()

	if isModify {
		err = project.Where("id=?", id).Find()
		if err != nil {
			logger.Errorln("Publish Project find error:", err)
			return
		}
		isAdmin := false
		if _, ok := user["isadmin"]; ok {
			isAdmin = user["isadmin"].(bool)
		}
		if project.Username != username && !isAdmin {
			err = NotModifyAuthorityErr
			return
		}

		util.ConvertAssign(project, form)
	} else {
		util.ConvertAssign(project, form)

		project.Username = username
		project.Ctime = util.TimeNow()
	}

	project.Uri = strings.ToLower(project.Uri)

	github := "github.com"
	pos := strings.Index(project.Src, github)
	if pos != -1 {
		project.Repo = project.Src[pos+len(github)+1:]
	}

	if !isModify {
		_, err = project.Insert()
	} else {
		err = project.Persist(project)
	}

	if err != nil {
		logger.Errorln("Publish Project error:", err)
	}

	// 發布項目,活躍度+10
	if uid, ok := user["uid"].(int); ok {
		weight := 10
		if isModify {
			weight = 2
		}
		go IncUserWeight("uid="+strconv.Itoa(uid), weight)
	}

	return
}
開發者ID:allenisready,項目名稱:studygolang,代碼行數:65,代碼來源:project.go


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