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


Golang Params.GetInt方法代碼示例

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


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

示例1: buildArgumentsRotate

func (server *Server) buildArgumentsRotate(arguments *list.List, params imageserver.Params) error {
	rotate, _ := params.GetInt("rotate")
	if rotate != 0 {
		if rotate < 0 || rotate > 359 {
			return &imageserver.ParamError{Param: "rotate", Message: "Invalid rotate parameter"}
		}

		arguments.PushBack("-rotate")
		arguments.PushBack(strconv.Itoa(rotate))
	}
	return nil
}
開發者ID:phamhongviet,項目名稱:imageserver,代碼行數:12,代碼來源:graphicsmagick.go

示例2: getDimension

func getDimension(name string, params imageserver.Params) (int, error) {
	if !params.Has(name) {
		return 0, nil
	}
	dimension, err := params.GetInt(name)
	if err != nil {
		return 0, err
	}
	if dimension < 0 {
		return 0, &imageserver.ParamError{Param: name, Message: "must be greater than or equal to 0"}
	}
	return dimension, nil
}
開發者ID:pierrre,項目名稱:imageserver,代碼行數:13,代碼來源:graphicsmagick.go

示例3: getDimension

func getDimension(name string, max int, params imageserver.Params) (uint, error) {
	if !params.Has(name) {
		return 0, nil
	}
	d, err := params.GetInt(name)
	if err != nil {
		return 0, err
	}
	if d < 0 {
		return 0, &imageserver.ParamError{Param: name, Message: "must be greater than or equal to 0"}
	}
	if max > 0 && d > max {
		return 0, &imageserver.ParamError{Param: name, Message: fmt.Sprintf("must be less than or equal to %d", max)}
	}
	return uint(d), nil
}
開發者ID:cautio,項目名稱:imageserver,代碼行數:16,代碼來源:nfntresize.go

示例4: TestParseQueryInt

func TestParseQueryInt(t *testing.T) {
	req, err := http.NewRequest("GET", "http://localhost?int=42", nil)
	if err != nil {
		t.Fatal(err)
	}
	params := imageserver.Params{}
	err = ParseQueryInt("int", req, params)
	if err != nil {
		t.Fatal(err)
	}
	i, err := params.GetInt("int")
	if err != nil {
		t.Fatal(err)
	}
	if i != 42 {
		t.Fatal("not equals")
	}
}
開發者ID:cautio,項目名稱:imageserver,代碼行數:18,代碼來源:parser_test.go

示例5: getQuality

func (enc *Encoder) getQuality(params imageserver.Params) (int, error) {
	if !params.Has("quality") {
		if enc.DefaultQuality != 0 {
			return enc.DefaultQuality, nil
		}
		return jpeg.DefaultQuality, nil
	}
	quality, err := params.GetInt("quality")
	if err != nil {
		return 0, err
	}
	if quality < 1 {
		return 0, &imageserver.ParamError{Param: "quality", Message: "must be greater than or equal to 1"}
	}
	if quality > 100 {
		return 0, &imageserver.ParamError{Param: "quality", Message: "must be less than or equal to 100"}
	}
	return quality, nil
}
開發者ID:pierrre,項目名稱:imageserver,代碼行數:19,代碼來源:jpeg.go

示例6: TestQualityParserParse

func TestQualityParserParse(t *testing.T) {
	parser := &QualityParser{}
	req, err := http.NewRequest("GET", "http://localhost?quality=50", nil)
	if err != nil {
		t.Fatal(err)
	}
	params := imageserver.Params{}
	err = parser.Parse(req, params)
	if err != nil {
		t.Fatal(err)
	}
	quality, err := params.GetInt("quality")
	if err != nil {
		t.Fatal(err)
	}
	if quality != 50 {
		t.Fatal("not equals")
	}
}
開發者ID:phamhongviet,項目名稱:imageserver,代碼行數:19,代碼來源:parser_test.go

示例7: buildArgumentsQuality

func (hdr *Handler) buildArgumentsQuality(arguments *list.List, params imageserver.Params, format string) error {
	if !params.Has("quality") {
		return nil
	}
	quality, err := params.GetInt("quality")
	if err != nil {
		return err
	}
	if quality < 0 {
		return &imageserver.ParamError{Param: "quality", Message: "must be greater than or equal to 0"}
	}
	if format == "jpeg" {
		if quality < 0 || quality > 100 {
			return &imageserver.ParamError{Param: "quality", Message: "must be between 0 and 100"}
		}
	}
	arguments.PushBack("-quality")
	arguments.PushBack(strconv.Itoa(quality))
	return nil
}
開發者ID:pierrre,項目名稱:imageserver,代碼行數:20,代碼來源:graphicsmagick.go

示例8: getBounds

func (prc *Processor) getBounds(params imageserver.Params) (image.Rectangle, error) {
	var bds image.Rectangle
	var err error
	bds.Min.X, err = params.GetInt("min_x")
	if err != nil {
		return image.ZR, err
	}
	bds.Min.Y, err = params.GetInt("min_y")
	if err != nil {
		return image.ZR, err
	}
	bds.Max.X, err = params.GetInt("max_x")
	if err != nil {
		return image.ZR, err
	}
	bds.Max.Y, err = params.GetInt("max_y")
	if err != nil {
		return image.ZR, err
	}
	return bds, nil
}
開發者ID:pierrre,項目名稱:imageserver,代碼行數:21,代碼來源:crop.go


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