本文整理匯總了Golang中github.com/pierrre/imageserver.Params.Has方法的典型用法代碼示例。如果您正苦於以下問題:Golang Params.Has方法的具體用法?Golang Params.Has怎麽用?Golang Params.Has使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pierrre/imageserver.Params
的用法示例。
在下文中一共展示了Params.Has方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getResampling
func (prc *ResizeProcessor) getResampling(params imageserver.Params) (gift.Resampling, error) {
if !params.Has("resampling") {
if prc.DefaultResampling != nil {
return prc.DefaultResampling, nil
}
return gift.NearestNeighborResampling, nil
}
rsp, err := params.GetString("resampling")
if err != nil {
return nil, err
}
switch rsp {
case "nearest_neighbor":
return gift.NearestNeighborResampling, nil
case "box":
return gift.BoxResampling, nil
case "linear":
return gift.LinearResampling, nil
case "cubic":
return gift.CubicResampling, nil
case "lanczos":
return gift.LanczosResampling, nil
}
return nil, &imageserver.ParamError{Param: "resampling", Message: "invalid value"}
}
示例2: getInterpolation
func (prc *Processor) getInterpolation(params imageserver.Params) (resize.InterpolationFunction, error) {
if !params.Has("interpolation") {
return prc.DefaultInterpolation, nil
}
interpolation, err := params.GetString("interpolation")
if err != nil {
return 0, err
}
switch interpolation {
case "nearest_neighbor":
return resize.NearestNeighbor, nil
case "bilinear":
return resize.Bilinear, nil
case "bicubic":
return resize.Bicubic, nil
case "mitchell_netravali":
return resize.MitchellNetravali, nil
case "lanczos2":
return resize.Lanczos2, nil
case "lanczos3":
return resize.Lanczos3, nil
default:
return 0, &imageserver.ParamError{Param: "interpolation", Message: "invalid value"}
}
}
示例3: buildArgumentsCrop
func (server *Server) buildArgumentsCrop(arguments *list.List, params imageserver.Params) error {
if !params.Has("crop") {
return nil
}
crop, _ := params.GetString("crop")
cropArgs := strings.Split(crop, ",")
cropArgsLen := len(cropArgs)
if cropArgsLen != 2 && cropArgsLen != 4 {
return &imageserver.ParamError{Param: "crop", Message: "Invalid crop request, parameters number mismatch"}
}
if cropArgsLen == 2 {
width, _ := strconv.Atoi(cropArgs[0])
height, _ := strconv.Atoi(cropArgs[1])
arguments.PushBack("-crop")
arguments.PushBack(fmt.Sprintf("%dx%d", width, height))
arguments.PushBack("+repage")
}
if cropArgsLen == 4 {
width, _ := strconv.Atoi(cropArgs[0])
height, _ := strconv.Atoi(cropArgs[1])
x, _ := strconv.Atoi(cropArgs[2])
y, _ := strconv.Atoi(cropArgs[3])
arguments.PushBack("-crop")
arguments.PushBack(fmt.Sprintf("%dx%d+%d+%d", width, height, x, y))
arguments.PushBack("+repage")
}
return nil
}
示例4: Change
// Change implements Processor.
func (proc *Processor) Change(params imageserver.Params) bool {
if !params.Has(Param) {
return false
}
params, err := params.GetParams(Param)
if err != nil {
return true
}
if params.Empty() {
return false
}
if params.Has("width") {
return true
}
if params.Has("height") {
return true
}
if params.Has("interpolation") {
return true
}
if params.Has("mode") {
return true
}
return false
}
示例5: TestParseQueryStringUndefined
func TestParseQueryStringUndefined(t *testing.T) {
req, err := http.NewRequest("GET", "http://localhost", nil)
if err != nil {
t.Fatal(err)
}
params := imageserver.Params{}
ParseQueryString("string", req, params)
if params.Has("string") {
t.Fatal("should not be set")
}
}
示例6: 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
}
示例7: Get
// Get implements Server.
func (srv *ValidateParamsServer) Get(params imageserver.Params) (*imageserver.Image, error) {
if params.Has(Param) {
params, err := params.GetParams(Param)
if err != nil {
return nil, err
}
err = srv.validate(params)
if err != nil {
return nil, wrapParamError(err)
}
}
return srv.Server.Get(params)
}
示例8: getBackground
func (prc *RotateProcessor) getBackground(params imageserver.Params) (color.Color, error) {
if !params.Has("background") {
return color.Transparent, nil
}
s, err := params.GetString("background")
if err != nil {
return nil, err
}
c, err := parseHexColor(s)
if err != nil {
return nil, &imageserver.ParamError{Param: "background", Message: err.Error()}
}
return c, nil
}
示例9: Process
// Process implements Processor.
func (proc *Processor) Process(nim image.Image, params imageserver.Params) (image.Image, error) {
if !params.Has(Param) {
return nim, nil
}
params, err := params.GetParams(Param)
if err != nil {
return nil, err
}
nim, err = process(nim, params)
if err != nil {
return nil, wrapParamError(err)
}
return nim, nil
}
示例10: Parse
// Parse implements Parser.
func (parser *FormatParser) Parse(req *http.Request, params imageserver.Params) error {
ParseQueryString("format", req, params)
if !params.Has("format") {
return nil
}
format, err := params.GetString("format")
if err != nil {
return err
}
if format == "jpg" {
format = "jpeg"
}
params.Set("format", format)
return nil
}
示例11: TestFormatParserParseUndefined
func TestFormatParserParseUndefined(t *testing.T) {
parser := &FormatParser{}
req, err := http.NewRequest("GET", "http://localhost", nil)
if err != nil {
t.Fatal(err)
}
params := imageserver.Params{}
err = parser.Parse(req, params)
if err != nil {
t.Fatal(err)
}
if params.Has("format") {
t.Fatal("should not be set")
}
}
示例12: parseSourceTransform
func parseSourceTransform(ps Parser, req *http.Request, params imageserver.Params, f func(string) string) error {
err := ps.Parse(req, params)
if err != nil {
return err
}
if !params.Has(imageserver.SourceParam) {
return nil
}
source, err := params.GetString(imageserver.SourceParam)
if err != nil {
return err
}
source = f(source)
params.Set(imageserver.SourceParam, source)
return nil
}
示例13: getHandler
func (hdr *FallbackHandler) getHandler(im *imageserver.Image, params imageserver.Params) (imageserver.Handler, error) {
if im.Format != "gif" {
return hdr.Fallback, nil
}
if !params.Has("format") {
return hdr.Handler, nil
}
format, err := params.GetString("format")
if err != nil {
return nil, err
}
if format != "gif" {
return hdr.Fallback, nil
}
return hdr.Handler, nil
}
示例14: getRotation
func (prc *RotateProcessor) getRotation(params imageserver.Params) (float32, error) {
if !params.Has("rotation") {
return 0, nil
}
rot, err := params.GetFloat("rotation")
if err != nil {
return 0, err
}
if rot < 0 {
rot = math.Mod(rot, 360) + 360
}
if rot >= 360 {
rot = math.Mod(rot, 360)
}
return float32(rot), nil
}
示例15: 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
}