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


Golang Request.Project方法代碼示例

本文整理匯總了Golang中net/http.Request.Project方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.Project方法的具體用法?Golang Request.Project怎麽用?Golang Request.Project使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net/http.Request的用法示例。


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

示例1: recordHandler

func recordHandler(w http.ResponseWriter, r *http.Request) {
	db, err := openDB()
	checkErr(err)
	path := r.URL.Path[len("/entry/"):]
	switch path {
	case "create":
		log.Print("Creating a new entry.")
		s, err := db.Prepare("INSERT INTO records(date,hours,project_id) values(?,?,?)")
		checkErr(err)
		h := r.FormValue("hours")
		m := r.FormValue("minutes")
		pID := r.FormValue("project")
		if h == "" || m == "" || pID == "" {
			errorHTTP(errors.New("A field you entered was blank."), w)
			return
		}
		duration, err := time.ParseDuration(fmt.Sprintf("%sh%sm", h, m))
		errorHTTP(err, w)
		project, err := strconv.ParseInt(pID, 10, 32)
		errorHTTP(err, w)
		_, err = s.Exec(time.Now(), duration.Hours(), project)
		errorHTTP(err, w)
		http.Redirect(w, r, "/entry/", http.StatusFound)
	default:
		projects, err := loadProjects(db)
		errorHTTP(err, w)
		recordsSQL, err := db.Query("SELECT * FROM records")
		errorHTTP(err, w)
		records := []Record{}
		total := make(map[string]float64)
		for recordsSQL.Next() {
			r := Record{}
			r.Project = &Project{}
			recordsSQL.Scan(&r.ID, &r.Date, &r.Hours, &r.Project.ID)
			for _, p := range projects {
				if r.Project.ID == p.ID {
					r.Project.Name = p.Name
				}
			}
			total[r.Project.Name] += r.Hours
			records = append(records, r)
		}
		data := struct {
			Projects []Project
			Records  []Record
			Total    map[string]float64
		}{
			projects,
			records,
			total,
		}
		err = templates.ExecuteTemplate(w, "logging.html", data)
		errorHTTP(err, w)
	}
}
開發者ID:exequielbc,項目名稱:clock,代碼行數:55,代碼來源:http.go

示例2: getReport

func getReport(w http.ResponseWriter, r *http.Request) {
	res := &Reports{}

	limit := 20
	if r.FormValue("count") != "" {
		limit, _ = strconv.Atoi(r.FormValue("count"))
	}

	dh := db.GetHandler()
	defer dh.Close()

	order := dh.OrderBy("start", genmai.DESC).Limit(limit + 1)

	var cond [][]interface{}

	re := regexp.MustCompile(`^/api/v1/reports/(\d+)$`)

	reportId := ""
	if m := re.FindStringSubmatch(r.URL.Path); m != nil {
		reportId = m[1]
	}

	if reportId != "" {
		cond = append(cond, []interface{}{"id", "=", reportId})
	}

	if projectId := r.FormValue("projectId"); projectId != "" {
		cond = append(cond, []interface{}{"project_id", "=", projectId})
	}

	if until := r.FormValue("until"); until != "" {
		u, _ := strconv.ParseInt(until, 10, 64)
		cond = append(cond, []interface{}{"start", "<=", time.Unix(u, 0)})
	}

	if since := r.FormValue("since"); since != "" {
		s, _ := strconv.ParseInt(since, 10, 64)
		cond = append(cond, []interface{}{"start", ">=", time.Unix(s, 0)})
	}

	if status := r.FormValue("status"); status != "" {
		cond = append(cond, []interface{}{"status", "=", status})
	}

	where := &genmai.Condition{}
	for i, c := range cond {
		if i < 1 {
			where = dh.Where(c[0], c[1], c[2])
		} else {
			where = where.And(dh.Where(c[0], c[1], c[2]))
		}
	}

	var reports []db.Report

	dh.Select(&reports, where, order)

	if len(reports) > limit {
		res.NextStart = reports[limit].Start.Unix()
		reports = reports[:len(reports)-1]
	}

	for _, report := range reports {
		r := &Report{
			Id:         report.Id,
			Status:     report.Status,
			Branch:     report.Branch,
			CompareUrl: report.CompareUrl,
			Start:      report.Start.Unix(),
			End:        report.End.Unix(),
		}

		var projects []db.Project
		dh.Select(&projects, dh.Where("id", "=", report.ProjectId))
		project := projects[0]

		r.Project = &Project{
			Id:   project.Id,
			Name: project.Name,
			Repo: project.Repo,
		}

		var commits []db.Commit
		dh.Select(&commits, dh.Where("report_id", "=", report.Id))
		for _, commit := range commits {
			r.Commits = append(r.Commits, &Commit{
				Revision: commit.Revision,
				Author:   commit.Author,
				Message:  commit.Message,
				Url:      commit.Url,
			})
		}

		var users []db.User
		dh.Select(&users, dh.Where("id", "=", report.TriggeredBy))
		user := users[0]
		r.TriggeredBy.Name = user.Name
		r.TriggeredBy.Url = user.Url
		r.TriggeredBy.AvatarUrl = user.AvatarUrl

//.........這裏部分代碼省略.........
開發者ID:walter-cd,項目名稱:walter-server,代碼行數:101,代碼來源:reports.go


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