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


Golang Part.Get方法代碼示例

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


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

示例1: Packaging

//Redundant
func Packaging(w http.ResponseWriter, r *http.Request, params martini.Params, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	id, err := strconv.Atoi(params["part"])
	if err != nil {
		apierror.GenerateError("Trouble getting part ID", err, w, r)
		return ""
	}
	p := products.Part{
		ID: id,
	}

	if err = p.Get(dtx); err != nil {
		apierror.GenerateError("Trouble getting part packages", err, w, r)
		return ""
	}
	return encoding.Must(enc.Encode(p.Packages))
}
開發者ID:ninnemana,項目名稱:API,代碼行數:17,代碼來源:part_ctlr.go

示例2: InstallSheet

//Sort of Redundant
func InstallSheet(w http.ResponseWriter, r *http.Request, params martini.Params, dtx *apicontext.DataContext) {
	id, err := strconv.Atoi(strings.Split(params["part"], ".")[0])
	if err != nil {
		apierror.GenerateError("Trouble getting part ID", err, w, r)
		return
	}
	p := products.Part{
		ID: id,
	}

	err = p.Get(dtx)
	if err != nil {
		apierror.GenerateError("Trouble getting part", err, w, r)
		return
	}
	var text string
	for _, content := range p.Content {
		if content.ContentType.Type == "installationSheet" {
			text = content.Text
		}
	}
	if text == "" {
		apierror.GenerateError("No Installation Sheet", err, w, r)
		return
	}

	data, err := rest.GetPDF(text, r)
	if err != nil {
		apierror.GenerateError("Error getting PDF", err, w, r)
		return
	}

	w.Header().Set("Content-Length", strconv.Itoa(len(data)))
	w.Header().Set("Content-Type", "application/pdf")
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
	w.Header().Set("Access-Control-Allow-Headers", "Origin")
	w.Write(data)
}
開發者ID:ninnemana,項目名稱:API,代碼行數:40,代碼來源:part_ctlr.go

示例3: ActiveApprovedReviews

//Redundant
func ActiveApprovedReviews(w http.ResponseWriter, r *http.Request, params martini.Params, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	id, err := strconv.Atoi(params["part"])
	if err != nil {
		apierror.GenerateError("Trouble getting part ID", err, w, r)
		return ""
	}
	p := products.Part{
		ID: id,
	}

	if err = p.Get(dtx); err != nil {
		apierror.GenerateError("Trouble getting part reviews", err, w, r)
		return ""
	}
	var revs []products.Review
	for _, rev := range p.Reviews {
		if rev.Active == true && rev.Approved == true {
			revs = append(revs, rev)
		}
	}

	return encoding.Must(enc.Encode(revs))
}
開發者ID:ninnemana,項目名稱:API,代碼行數:24,代碼來源:part_ctlr.go

示例4: Prices

func Prices(w http.ResponseWriter, r *http.Request, params martini.Params, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	id, err := strconv.Atoi(params["part"])
	if err != nil {
		apierror.GenerateError("Trouble getting part ID", err, w, r)
		return ""
	}
	p := products.Part{
		ID: id,
	}

	priceChan := make(chan int)
	custChan := make(chan int)

	go func() {
		err = p.Get(dtx)
		priceChan <- 1
	}()

	go func() {
		price, custErr := customer.GetCustomerPrice(dtx, p.ID)
		if custErr != nil {
			err = custErr
		}
		p.Pricing = append(p.Pricing, products.Price{0, 0, "Customer", price, false, time.Now()})
		custChan <- 1
	}()

	<-priceChan
	<-custChan

	if err != nil {
		apierror.GenerateError("Trouble getting part prices", err, w, r)
		return ""
	}

	return encoding.Must(enc.Encode(p.Pricing))
}
開發者ID:ninnemana,項目名稱:API,代碼行數:37,代碼來源:part_ctlr.go


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