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


Golang Params.String方法代碼示例

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


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

示例1: TestRotateParserParse

func TestRotateParserParse(t *testing.T) {
	type TC struct {
		query              url.Values
		expectedParams     imageserver.Params
		expectedParamError string
	}
	for _, tc := range []TC{
		{},
		{
			query: url.Values{"rotation": {"90"}},
			expectedParams: imageserver.Params{rotateParam: imageserver.Params{
				"rotation": 90.0,
			}},
		},
		{
			query: url.Values{"interpolation": {"cubic"}},
			expectedParams: imageserver.Params{rotateParam: imageserver.Params{
				"interpolation": "cubic",
			}},
		},
		{
			query: url.Values{"background": {"FF0000"}},
			expectedParams: imageserver.Params{rotateParam: imageserver.Params{
				"background": "FF0000",
			}},
		},
		{
			query:              url.Values{"rotation": {"invalid"}},
			expectedParamError: rotateParam + ".rotation",
		},
	} {
		func() {
			defer func() {
				if t.Failed() {
					t.Logf("%#v", tc)
				}
			}()
			u := &url.URL{
				Scheme:   "http",
				Host:     "localhost",
				RawQuery: tc.query.Encode(),
			}
			req, err := http.NewRequest("GET", u.String(), nil)
			if err != nil {
				t.Fatal(err)
			}
			prc := &RotateParser{}
			params := imageserver.Params{}
			err = prc.Parse(req, params)
			if err != nil {
				if err, ok := err.(*imageserver.ParamError); ok && tc.expectedParamError == err.Param {
					return
				}
				t.Fatal(err)
			}
			if params.String() != tc.expectedParams.String() {
				t.Fatalf("unexpected params: got %s, want %s", params, tc.expectedParams)
			}
		}()
	}
}
開發者ID:xiangxi,項目名稱:imageserver,代碼行數:61,代碼來源:rotate_test.go

示例2: TestParse

func TestParse(t *testing.T) {
	p := &Parser{}
	for _, tc := range []struct {
		name               string
		query              url.Values
		expectedParams     imageserver.Params
		expectedParamError string
	}{
		{
			name: "Empty",
		},
		{
			name:  "Width",
			query: url.Values{"width": {"100"}},
			expectedParams: imageserver.Params{globalParam: imageserver.Params{
				"width": 100,
			}},
		},
		{
			name:  "Height",
			query: url.Values{"height": {"100"}},
			expectedParams: imageserver.Params{globalParam: imageserver.Params{
				"height": 100,
			}},
		},
		{
			name:  "Interpolation",
			query: url.Values{"interpolation": {"lanczos3"}},
			expectedParams: imageserver.Params{globalParam: imageserver.Params{
				"interpolation": "lanczos3",
			}},
		},
		{
			name:  "Mode",
			query: url.Values{"mode": {"resize"}},
			expectedParams: imageserver.Params{globalParam: imageserver.Params{
				"mode": "resize",
			}},
		},
		{
			name:               "WidthInvalid",
			query:              url.Values{"width": {"invalid"}},
			expectedParamError: globalParam + ".width",
		},
		{
			name:               "HeightInvalid",
			query:              url.Values{"height": {"invalid"}},
			expectedParamError: globalParam + ".height",
		},
	} {
		t.Run(tc.name, func(t *testing.T) {
			u := &url.URL{
				Scheme:   "http",
				Host:     "localhost",
				RawQuery: tc.query.Encode(),
			}
			req, err := http.NewRequest("GET", u.String(), nil)
			if err != nil {
				t.Fatal(err)
			}
			params := imageserver.Params{}
			err = p.Parse(req, params)
			if err != nil {
				if err, ok := err.(*imageserver.ParamError); ok && tc.expectedParamError == err.Param {
					return
				}
				t.Fatal(err)
			}
			if params.String() != tc.expectedParams.String() {
				t.Fatalf("unexpected params: got %s, want %s", params, tc.expectedParams)
			}
		})
	}
}
開發者ID:pierrre,項目名稱:imageserver,代碼行數:74,代碼來源:nfntresize_test.go

示例3: TestParse


//.........這裏部分代碼省略.........
		{
			name:  "OnlyEnlargeSmaller",
			query: url.Values{"only_enlarge_smaller": {"true"}},
			expectedParams: imageserver.Params{globalParam: imageserver.Params{
				"only_enlarge_smaller": true,
			}},
		},
		{
			name:  "Background",
			query: url.Values{"background": {"123abc"}},
			expectedParams: imageserver.Params{globalParam: imageserver.Params{
				"background": "123abc",
			}},
		},
		{
			name:  "Extent",
			query: url.Values{"extent": {"true"}},
			expectedParams: imageserver.Params{globalParam: imageserver.Params{
				"extent": true,
			}},
		},
		{
			name:  "Format",
			query: url.Values{"format": {"jpeg"}},
			expectedParams: imageserver.Params{globalParam: imageserver.Params{
				"format": "jpeg",
			}},
		},
		{
			name:  "Quality",
			query: url.Values{"quality": {"75"}},
			expectedParams: imageserver.Params{globalParam: imageserver.Params{
				"quality": 75,
			}},
		},
		{
			name:               "WidthInvalid",
			query:              url.Values{"width": {"invalid"}},
			expectedParamError: globalParam + ".width",
		},
		{
			name:               "HeightInvalid",
			query:              url.Values{"height": {"invalid"}},
			expectedParamError: globalParam + ".height",
		},
		{
			name:               "FillInvalid",
			query:              url.Values{"fill": {"invalid"}},
			expectedParamError: globalParam + ".fill",
		},
		{
			name:               "IgnoreRatioInvalid",
			query:              url.Values{"ignore_ratio": {"invalid"}},
			expectedParamError: globalParam + ".ignore_ratio",
		},
		{
			name:               "OnlyShrinkLargerInvalid",
			query:              url.Values{"only_shrink_larger": {"invalid"}},
			expectedParamError: globalParam + ".only_shrink_larger",
		},
		{
			name:               "OnlyEnlargeSmallerInvalid",
			query:              url.Values{"only_enlarge_smaller": {"invalid"}},
			expectedParamError: globalParam + ".only_enlarge_smaller",
		},
		{
			name:               "ExtentInvalid",
			query:              url.Values{"extent": {"invalid"}},
			expectedParamError: globalParam + ".extent",
		},
		{
			name:               "QualityInvalid",
			query:              url.Values{"quality": {"invalid"}},
			expectedParamError: globalParam + ".quality",
		},
	} {
		t.Run(tc.name, func(t *testing.T) {
			u := &url.URL{
				Scheme:   "http",
				Host:     "localhost",
				RawQuery: tc.query.Encode(),
			}
			req, err := http.NewRequest("GET", u.String(), nil)
			if err != nil {
				t.Fatal(err)
			}
			params := imageserver.Params{}
			err = p.Parse(req, params)
			if err != nil {
				if err, ok := err.(*imageserver.ParamError); ok && tc.expectedParamError == err.Param {
					return
				}
				t.Fatal(err)
			}
			if params.String() != tc.expectedParams.String() {
				t.Fatalf("unexpected params: got %s, want %s", params, tc.expectedParams)
			}
		})
	}
}
開發者ID:pierrre,項目名稱:imageserver,代碼行數:101,代碼來源:graphicsmagick_test.go

示例4: TestParse

func TestParse(t *testing.T) {
	type TC struct {
		query              url.Values
		expectedParams     imageserver.Params
		expectedParamError string
	}
	for _, tc := range []TC{
		{},
		{
			query: url.Values{"width": {"100"}},
			expectedParams: imageserver.Params{Param: imageserver.Params{
				"width": 100,
			}},
		},
		{
			query: url.Values{"height": {"100"}},
			expectedParams: imageserver.Params{Param: imageserver.Params{
				"height": 100,
			}},
		},
		{
			query: url.Values{"resampling": {"lanczos"}},
			expectedParams: imageserver.Params{Param: imageserver.Params{
				"resampling": "lanczos",
			}},
		},
		{
			query: url.Values{"mode": {"fit"}},
			expectedParams: imageserver.Params{Param: imageserver.Params{
				"mode": "fit",
			}},
		},
		{
			query:              url.Values{"width": {"invalid"}},
			expectedParamError: Param + ".width",
		},
		{
			query:              url.Values{"height": {"invalid"}},
			expectedParamError: Param + ".height",
		},
	} {
		func() {
			defer func() {
				if t.Failed() {
					t.Logf("%#v", tc)
				}
			}()
			u := &url.URL{
				Scheme:   "http",
				Host:     "localhost",
				RawQuery: tc.query.Encode(),
			}
			req, err := http.NewRequest("GET", u.String(), nil)
			if err != nil {
				t.Fatal(err)
			}
			p := &Parser{}
			params := imageserver.Params{}
			err = p.Parse(req, params)
			if err != nil {
				if err, ok := err.(*imageserver.ParamError); ok && tc.expectedParamError == err.Param {
					return
				}
				t.Fatal(err)
			}
			if params.String() != tc.expectedParams.String() {
				t.Fatalf("unexpected params: got %s, want %s", params, tc.expectedParams)
			}
		}()
	}
}
開發者ID:cautio,項目名稱:imageserver,代碼行數:71,代碼來源:gift_test.go

示例5: TestRotateParserParse

func TestRotateParserParse(t *testing.T) {
	prs := &RotateParser{}
	for _, tc := range []struct {
		name               string
		query              url.Values
		expectedParams     imageserver.Params
		expectedParamError string
	}{
		{
			name: "Empty",
		},
		{
			name:  "Rotation",
			query: url.Values{"rotation": {"90"}},
			expectedParams: imageserver.Params{rotateParam: imageserver.Params{
				"rotation": 90.0,
			}},
		},
		{
			name:  "Interpolation",
			query: url.Values{"interpolation": {"cubic"}},
			expectedParams: imageserver.Params{rotateParam: imageserver.Params{
				"interpolation": "cubic",
			}},
		},
		{
			name:  "Background",
			query: url.Values{"background": {"FF0000"}},
			expectedParams: imageserver.Params{rotateParam: imageserver.Params{
				"background": "FF0000",
			}},
		},
		{
			name:               "RotationInvalid",
			query:              url.Values{"rotation": {"invalid"}},
			expectedParamError: rotateParam + ".rotation",
		},
	} {
		t.Run(tc.name, func(t *testing.T) {
			u := &url.URL{
				Scheme:   "http",
				Host:     "localhost",
				RawQuery: tc.query.Encode(),
			}
			req, err := http.NewRequest("GET", u.String(), nil)
			if err != nil {
				t.Fatal(err)
			}
			params := imageserver.Params{}
			err = prs.Parse(req, params)
			if err != nil {
				if err, ok := err.(*imageserver.ParamError); ok && tc.expectedParamError == err.Param {
					return
				}
				t.Fatal(err)
			}
			if params.String() != tc.expectedParams.String() {
				t.Fatalf("unexpected params: got %s, want %s", params, tc.expectedParams)
			}
		})
	}
}
開發者ID:pierrre,項目名稱:imageserver,代碼行數:62,代碼來源:rotate_test.go

示例6: TestParse


//.........這裏部分代碼省略.........
			expectedParamError: globalParam + ".ignore_ratio",
		},

		{
			query:              url.Values{"fill": {"invalid"}},
			expectedParamError: globalParam + ".fill",
		},
		{
			query:              url.Values{"only_shrink_larger": {"invalid"}},
			expectedParamError: globalParam + ".only_shrink_larger",
		},
		{
			query:              url.Values{"only_enlarge_smaller": {"invalid"}},
			expectedParamError: globalParam + ".only_enlarge_smaller",
		},
		{
			query:              url.Values{"extent": {"invalid"}},
			expectedParamError: globalParam + ".extent",
		},
		{
			query:              url.Values{"monochrome": {"invalid"}},
			expectedParamError: globalParam + ".monochrome",
		},
		{
			query:              url.Values{"grey": {"invalid"}},
			expectedParamError: globalParam + ".grey",
		},
		{
			query:              url.Values{"no_strip": {"invalid"}},
			expectedParamError: globalParam + ".no_strip",
		},
		{
			query:              url.Values{"trim": {"invalid"}},
			expectedParamError: globalParam + ".trim",
		},
		{
			query:              url.Values{"no_interlace": {"invalid"}},
			expectedParamError: globalParam + ".no_interlace",
		},
		{
			query:              url.Values{"flip": {"invalid"}},
			expectedParamError: globalParam + ".flip",
		},
		{
			query:              url.Values{"flop": {"invalid"}},
			expectedParamError: globalParam + ".flop",
		},

		{
			query:              url.Values{"w": {"invalid"}},
			expectedParamError: globalParam + ".w",
		},
		{
			query:              url.Values{"h": {"invalid"}},
			expectedParamError: globalParam + ".h",
		},
		{
			query:              url.Values{"rotate": {"invalid"}},
			expectedParamError: globalParam + ".rotate",
		},
		{
			query:              url.Values{"density": {"invalid"}},
			expectedParamError: globalParam + ".density",
		},

		{
			query:              url.Values{"q": {"invalid"}},
			expectedParamError: globalParam + ".q",
		},
	} {
		func() {
			defer func() {
				if t.Failed() {
					t.Logf("%#v", tc)
				}
			}()
			u := &url.URL{
				Scheme:   "http",
				Host:     "localhost",
				RawQuery: tc.query.Encode(),
			}
			req, err := http.NewRequest("GET", u.String(), nil)
			if err != nil {
				t.Fatal(err)
			}
			p := &Parser{}
			params := imageserver.Params{}
			err = p.Parse(req, params)
			if err != nil {
				if err, ok := err.(*imageserver.ParamError); ok && tc.expectedParamError == err.Param {
					return
				}
				t.Fatal(err)
			}
			if params.String() != tc.expectedParams.String() {
				t.Fatalf("unexpected params: got %s, want %s", params, tc.expectedParams)
			}
		}()
	}
}
開發者ID:phamhongviet,項目名稱:imageserver,代碼行數:101,代碼來源:graphicsmagick_test.go

示例7: TestParse


//.........這裏部分代碼省略.........
		},
		{
			query: url.Values{"only_shrink_larger": {"true"}},
			expectedParams: imageserver.Params{globalParam: imageserver.Params{
				"only_shrink_larger": true,
			}},
		},
		{
			query: url.Values{"only_enlarge_smaller": {"true"}},
			expectedParams: imageserver.Params{globalParam: imageserver.Params{
				"only_enlarge_smaller": true,
			}},
		},
		{
			query: url.Values{"background": {"123abc"}},
			expectedParams: imageserver.Params{globalParam: imageserver.Params{
				"background": "123abc",
			}},
		},
		{
			query: url.Values{"extent": {"true"}},
			expectedParams: imageserver.Params{globalParam: imageserver.Params{
				"extent": true,
			}},
		},
		{
			query: url.Values{"format": {"jpeg"}},
			expectedParams: imageserver.Params{globalParam: imageserver.Params{
				"format": "jpeg",
			}},
		},
		{
			query: url.Values{"quality": {"75"}},
			expectedParams: imageserver.Params{globalParam: imageserver.Params{
				"quality": 75,
			}},
		},
		{
			query:              url.Values{"width": {"invalid"}},
			expectedParamError: globalParam + ".width",
		},
		{
			query:              url.Values{"height": {"invalid"}},
			expectedParamError: globalParam + ".height",
		},
		{
			query:              url.Values{"fill": {"invalid"}},
			expectedParamError: globalParam + ".fill",
		},
		{
			query:              url.Values{"ignore_ratio": {"invalid"}},
			expectedParamError: globalParam + ".ignore_ratio",
		},
		{
			query:              url.Values{"only_shrink_larger": {"invalid"}},
			expectedParamError: globalParam + ".only_shrink_larger",
		},
		{
			query:              url.Values{"only_enlarge_smaller": {"invalid"}},
			expectedParamError: globalParam + ".only_enlarge_smaller",
		},
		{
			query:              url.Values{"extent": {"invalid"}},
			expectedParamError: globalParam + ".extent",
		},
		{
			query:              url.Values{"quality": {"invalid"}},
			expectedParamError: globalParam + ".quality",
		},
	} {
		func() {
			defer func() {
				if t.Failed() {
					t.Logf("%#v", tc)
				}
			}()
			u := &url.URL{
				Scheme:   "http",
				Host:     "localhost",
				RawQuery: tc.query.Encode(),
			}
			req, err := http.NewRequest("GET", u.String(), nil)
			if err != nil {
				t.Fatal(err)
			}
			p := &Parser{}
			params := imageserver.Params{}
			err = p.Parse(req, params)
			if err != nil {
				if err, ok := err.(*imageserver.ParamError); ok && tc.expectedParamError == err.Param {
					return
				}
				t.Fatal(err)
			}
			if params.String() != tc.expectedParams.String() {
				t.Fatalf("unexpected params: got %s, want %s", params, tc.expectedParams)
			}
		}()
	}
}
開發者ID:cautio,項目名稱:imageserver,代碼行數:101,代碼來源:graphicsmagick_test.go


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