Best K6 code snippet using html.Map
mediatype_test.go
Source:mediatype_test.go
1// Copyright 2010 The Go Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.4package mime5import (6 "reflect"7 "strings"8 "testing"9)10func TestConsumeToken(t *testing.T) {11 tests := [...][3]string{12 {"foo bar", "foo", " bar"},13 {"bar", "bar", ""},14 {"", "", ""},15 {" foo", "", " foo"},16 }17 for _, test := range tests {18 token, rest := consumeToken(test[0])19 expectedToken := test[1]20 expectedRest := test[2]21 if token != expectedToken {22 t.Errorf("expected to consume token '%s', not '%s' from '%s'",23 expectedToken, token, test[0])24 } else if rest != expectedRest {25 t.Errorf("expected to have left '%s', not '%s' after reading token '%s' from '%s'",26 expectedRest, rest, token, test[0])27 }28 }29}30func TestConsumeValue(t *testing.T) {31 tests := [...][3]string{32 {"foo bar", "foo", " bar"},33 {"bar", "bar", ""},34 {" bar ", "", " bar "},35 {`"My value"end`, "My value", "end"},36 {`"My value" end`, "My value", " end"},37 {`"\\" rest`, "\\", " rest"},38 {`"My \" value"end`, "My \" value", "end"},39 {`"\" rest`, "", `"\" rest`},40 {`"C:\dev\go\robots.txt"`, `C:\dev\go\robots.txt`, ""},41 {`"C:\æ°å»ºæ件件\ä¸æ第äºæ¬¡æµè¯.mp4"`, `C:\æ°å»ºæ件件\ä¸æ第äºæ¬¡æµè¯.mp4`, ""},42 }43 for _, test := range tests {44 value, rest := consumeValue(test[0])45 expectedValue := test[1]46 expectedRest := test[2]47 if value != expectedValue {48 t.Errorf("expected to consume value [%s], not [%s] from [%s]",49 expectedValue, value, test[0])50 } else if rest != expectedRest {51 t.Errorf("expected to have left [%s], not [%s] after reading value [%s] from [%s]",52 expectedRest, rest, value, test[0])53 }54 }55}56func TestConsumeMediaParam(t *testing.T) {57 tests := [...][4]string{58 {" ; foo=bar", "foo", "bar", ""},59 {"; foo=bar", "foo", "bar", ""},60 {";foo=bar", "foo", "bar", ""},61 {";FOO=bar", "foo", "bar", ""},62 {`;foo="bar"`, "foo", "bar", ""},63 {`;foo="bar"; `, "foo", "bar", "; "},64 {`;foo="bar"; foo=baz`, "foo", "bar", "; foo=baz"},65 {` ; boundary=----CUT;`, "boundary", "----CUT", ";"},66 {` ; key=value; blah="value";name="foo" `, "key", "value", `; blah="value";name="foo" `},67 {`; blah="value";name="foo" `, "blah", "value", `;name="foo" `},68 {`;name="foo" `, "name", "foo", ` `},69 }70 for _, test := range tests {71 param, value, rest := consumeMediaParam(test[0])72 expectedParam := test[1]73 expectedValue := test[2]74 expectedRest := test[3]75 if param != expectedParam {76 t.Errorf("expected to consume param [%s], not [%s] from [%s]",77 expectedParam, param, test[0])78 } else if value != expectedValue {79 t.Errorf("expected to consume value [%s], not [%s] from [%s]",80 expectedValue, value, test[0])81 } else if rest != expectedRest {82 t.Errorf("expected to have left [%s], not [%s] after reading [%s/%s] from [%s]",83 expectedRest, rest, param, value, test[0])84 }85 }86}87type mediaTypeTest struct {88 in string89 t string90 p map[string]string91}92func TestParseMediaType(t *testing.T) {93 // Convenience map initializer94 m := func(s ...string) map[string]string {95 sm := make(map[string]string)96 for i := 0; i < len(s); i += 2 {97 sm[s[i]] = s[i+1]98 }99 return sm100 }101 nameFoo := map[string]string{"name": "foo"}102 tests := []mediaTypeTest{103 {`form-data; name="foo"`, "form-data", nameFoo},104 {` form-data ; name=foo`, "form-data", nameFoo},105 {`FORM-DATA;name="foo"`, "form-data", nameFoo},106 {` FORM-DATA ; name="foo"`, "form-data", nameFoo},107 {` FORM-DATA ; name="foo"`, "form-data", nameFoo},108 {`form-data; key=value; blah="value";name="foo" `,109 "form-data",110 m("key", "value", "blah", "value", "name", "foo")},111 {`foo; key=val1; key=the-key-appears-again-which-is-bogus`,112 "", m()},113 // From RFC 2231:114 {`application/x-stuff; title*=us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A`,115 "application/x-stuff",116 m("title", "This is ***fun***")},117 {`message/external-body; access-type=URL; ` +118 `URL*0="ftp://";` +119 `URL*1="cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"`,120 "message/external-body",121 m("access-type", "URL",122 "url", "ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar")},123 {`application/x-stuff; ` +124 `title*0*=us-ascii'en'This%20is%20even%20more%20; ` +125 `title*1*=%2A%2A%2Afun%2A%2A%2A%20; ` +126 `title*2="isn't it!"`,127 "application/x-stuff",128 m("title", "This is even more ***fun*** isn't it!")},129 // Tests from http://greenbytes.de/tech/tc2231/130 // Note: Backslash escape handling is a bit loose, like MSIE.131 // #attonly132 {`attachment`,133 "attachment",134 m()},135 // #attonlyucase136 {`ATTACHMENT`,137 "attachment",138 m()},139 // #attwithasciifilename140 {`attachment; filename="foo.html"`,141 "attachment",142 m("filename", "foo.html")},143 // #attwithasciifilename25144 {`attachment; filename="0000000000111111111122222"`,145 "attachment",146 m("filename", "0000000000111111111122222")},147 // #attwithasciifilename35148 {`attachment; filename="00000000001111111111222222222233333"`,149 "attachment",150 m("filename", "00000000001111111111222222222233333")},151 // #attwithasciifnescapedchar152 {`attachment; filename="f\oo.html"`,153 "attachment",154 m("filename", "f\\oo.html")},155 // #attwithasciifnescapedquote156 {`attachment; filename="\"quoting\" tested.html"`,157 "attachment",158 m("filename", `"quoting" tested.html`)},159 // #attwithquotedsemicolon160 {`attachment; filename="Here's a semicolon;.html"`,161 "attachment",162 m("filename", "Here's a semicolon;.html")},163 // #attwithfilenameandextparam164 {`attachment; foo="bar"; filename="foo.html"`,165 "attachment",166 m("foo", "bar", "filename", "foo.html")},167 // #attwithfilenameandextparamescaped168 {`attachment; foo="\"\\";filename="foo.html"`,169 "attachment",170 m("foo", "\"\\", "filename", "foo.html")},171 // #attwithasciifilenameucase172 {`attachment; FILENAME="foo.html"`,173 "attachment",174 m("filename", "foo.html")},175 // #attwithasciifilenamenq176 {`attachment; filename=foo.html`,177 "attachment",178 m("filename", "foo.html")},179 // #attwithasciifilenamenqs180 {`attachment; filename=foo.html ;`,181 "attachment",182 m("filename", "foo.html")},183 // #attwithfntokensq184 {`attachment; filename='foo.html'`,185 "attachment",186 m("filename", "'foo.html'")},187 // #attwithisofnplain188 {`attachment; filename="foo-ä.html"`,189 "attachment",190 m("filename", "foo-ä.html")},191 // #attwithutf8fnplain192 {`attachment; filename="foo-ä.html"`,193 "attachment",194 m("filename", "foo-ä.html")},195 // #attwithfnrawpctenca196 {`attachment; filename="foo-%41.html"`,197 "attachment",198 m("filename", "foo-%41.html")},199 // #attwithfnusingpct200 {`attachment; filename="50%.html"`,201 "attachment",202 m("filename", "50%.html")},203 // #attwithfnrawpctencaq204 {`attachment; filename="foo-%\41.html"`,205 "attachment",206 m("filename", "foo-%\\41.html")},207 // #attwithnamepct208 {`attachment; name="foo-%41.html"`,209 "attachment",210 m("name", "foo-%41.html")},211 // #attwithfilenamepctandiso212 {`attachment; name="ä-%41.html"`,213 "attachment",214 m("name", "ä-%41.html")},215 // #attwithfnrawpctenclong216 {`attachment; filename="foo-%c3%a4-%e2%82%ac.html"`,217 "attachment",218 m("filename", "foo-%c3%a4-%e2%82%ac.html")},219 // #attwithasciifilenamews1220 {`attachment; filename ="foo.html"`,221 "attachment",222 m("filename", "foo.html")},223 // #attmissingdisposition224 {`filename=foo.html`,225 "", m()},226 // #attmissingdisposition2227 {`x=y; filename=foo.html`,228 "", m()},229 // #attmissingdisposition3230 {`"foo; filename=bar;baz"; filename=qux`,231 "", m()},232 // #attmissingdisposition4233 {`filename=foo.html, filename=bar.html`,234 "", m()},235 // #emptydisposition236 {`; filename=foo.html`,237 "", m()},238 // #doublecolon239 {`: inline; attachment; filename=foo.html`,240 "", m()},241 // #attandinline242 {`inline; attachment; filename=foo.html`,243 "", m()},244 // #attandinline2245 {`attachment; inline; filename=foo.html`,246 "", m()},247 // #attbrokenquotedfn248 {`attachment; filename="foo.html".txt`,249 "", m()},250 // #attbrokenquotedfn2251 {`attachment; filename="bar`,252 "", m()},253 // #attbrokenquotedfn3254 {`attachment; filename=foo"bar;baz"qux`,255 "", m()},256 // #attmultinstances257 {`attachment; filename=foo.html, attachment; filename=bar.html`,258 "", m()},259 // #attmissingdelim260 {`attachment; foo=foo filename=bar`,261 "", m()},262 // #attmissingdelim2263 {`attachment; filename=bar foo=foo`,264 "", m()},265 // #attmissingdelim3266 {`attachment filename=bar`,267 "", m()},268 // #attreversed269 {`filename=foo.html; attachment`,270 "", m()},271 // #attconfusedparam272 {`attachment; xfilename=foo.html`,273 "attachment",274 m("xfilename", "foo.html")},275 // #attcdate276 {`attachment; creation-date="Wed, 12 Feb 1997 16:29:51 -0500"`,277 "attachment",278 m("creation-date", "Wed, 12 Feb 1997 16:29:51 -0500")},279 // #attmdate280 {`attachment; modification-date="Wed, 12 Feb 1997 16:29:51 -0500"`,281 "attachment",282 m("modification-date", "Wed, 12 Feb 1997 16:29:51 -0500")},283 // #dispext284 {`foobar`, "foobar", m()},285 // #dispextbadfn286 {`attachment; example="filename=example.txt"`,287 "attachment",288 m("example", "filename=example.txt")},289 // #attwithfn2231utf8290 {`attachment; filename*=UTF-8''foo-%c3%a4-%e2%82%ac.html`,291 "attachment",292 m("filename", "foo-ä-â¬.html")},293 // #attwithfn2231noc294 {`attachment; filename*=''foo-%c3%a4-%e2%82%ac.html`,295 "attachment",296 m()},297 // #attwithfn2231utf8comp298 {`attachment; filename*=UTF-8''foo-a%cc%88.html`,299 "attachment",300 m("filename", "foo-aÌ.html")},301 // #attwithfn2231ws2302 {`attachment; filename*= UTF-8''foo-%c3%a4.html`,303 "attachment",304 m("filename", "foo-ä.html")},305 // #attwithfn2231ws3306 {`attachment; filename* =UTF-8''foo-%c3%a4.html`,307 "attachment",308 m("filename", "foo-ä.html")},309 // #attwithfn2231quot310 {`attachment; filename*="UTF-8''foo-%c3%a4.html"`,311 "attachment",312 m("filename", "foo-ä.html")},313 // #attwithfn2231quot2314 {`attachment; filename*="foo%20bar.html"`,315 "attachment",316 m()},317 // #attwithfn2231singleqmissing318 {`attachment; filename*=UTF-8'foo-%c3%a4.html`,319 "attachment",320 m()},321 // #attwithfn2231nbadpct1322 {`attachment; filename*=UTF-8''foo%`,323 "attachment",324 m()},325 // #attwithfn2231nbadpct2326 {`attachment; filename*=UTF-8''f%oo.html`,327 "attachment",328 m()},329 // #attwithfn2231dpct330 {`attachment; filename*=UTF-8''A-%2541.html`,331 "attachment",332 m("filename", "A-%41.html")},333 // #attfncont334 {`attachment; filename*0="foo."; filename*1="html"`,335 "attachment",336 m("filename", "foo.html")},337 // #attfncontenc338 {`attachment; filename*0*=UTF-8''foo-%c3%a4; filename*1=".html"`,339 "attachment",340 m("filename", "foo-ä.html")},341 // #attfncontlz342 {`attachment; filename*0="foo"; filename*01="bar"`,343 "attachment",344 m("filename", "foo")},345 // #attfncontnc346 {`attachment; filename*0="foo"; filename*2="bar"`,347 "attachment",348 m("filename", "foo")},349 // #attfnconts1350 {`attachment; filename*1="foo."; filename*2="html"`,351 "attachment", m()},352 // #attfncontord353 {`attachment; filename*1="bar"; filename*0="foo"`,354 "attachment",355 m("filename", "foobar")},356 // #attfnboth357 {`attachment; filename="foo-ae.html"; filename*=UTF-8''foo-%c3%a4.html`,358 "attachment",359 m("filename", "foo-ä.html")},360 // #attfnboth2361 {`attachment; filename*=UTF-8''foo-%c3%a4.html; filename="foo-ae.html"`,362 "attachment",363 m("filename", "foo-ä.html")},364 // #attfnboth3365 {`attachment; filename*0*=ISO-8859-15''euro-sign%3d%a4; filename*=ISO-8859-1''currency-sign%3d%a4`,366 "attachment",367 m()},368 // #attnewandfn369 {`attachment; foobar=x; filename="foo.html"`,370 "attachment",371 m("foobar", "x", "filename", "foo.html")},372 // Browsers also just send UTF-8 directly without RFC 2231,373 // at least when the source page is served with UTF-8.374 {`form-data; firstname="ÐÑÑд"; lastname="ФиÑпаÑÑик"`,375 "form-data",376 m("firstname", "ÐÑÑд", "lastname", "ФиÑпаÑÑик")},377 // Empty string used to be mishandled.378 {`foo; bar=""`, "foo", m("bar", "")},379 // Microsoft browers in intranet mode do not think they need to escape \ in file name.380 {`form-data; name="file"; filename="C:\dev\go\robots.txt"`, "form-data", m("name", "file", "filename", `C:\dev\go\robots.txt`)},381 {`form-data; name="file"; filename="C:\æ°å»ºæ件件\ä¸æ第äºæ¬¡æµè¯.mp4"`, "form-data", m("name", "file", "filename", `C:\æ°å»ºæ件件\ä¸æ第äºæ¬¡æµè¯.mp4`)},382 }383 for _, test := range tests {384 mt, params, err := ParseMediaType(test.in)385 if err != nil {386 if test.t != "" {387 t.Errorf("for input %#q, unexpected error: %v", test.in, err)388 continue389 }390 continue391 }392 if g, e := mt, test.t; g != e {393 t.Errorf("for input %#q, expected type %q, got %q",394 test.in, e, g)395 continue396 }397 if len(params) == 0 && len(test.p) == 0 {398 continue399 }400 if !reflect.DeepEqual(params, test.p) {401 t.Errorf("for input %#q, wrong params.\n"+402 "expected: %#v\n"+403 " got: %#v",404 test.in, test.p, params)405 }406 }407}408type badMediaTypeTest struct {409 in string410 mt string411 err string412}413var badMediaTypeTests = []badMediaTypeTest{414 {"bogus ;=========", "bogus", "mime: invalid media parameter"},415 // The following example is from real email delivered by gmail (error: missing semicolon)416 // and it is there to check behavior described in #19498417 {"application/pdf; x-mac-type=\"3F3F3F3F\"; x-mac-creator=\"3F3F3F3F\" name=\"a.pdf\";",418 "application/pdf", "mime: invalid media parameter"},419 {"bogus/<script>alert</script>", "", "mime: expected token after slash"},420 {"bogus/bogus<script>alert</script>", "", "mime: unexpected content after media subtype"},421 // Tests from http://greenbytes.de/tech/tc2231/422 {`"attachment"`, "attachment", "mime: no media type"},423 {"attachment; filename=foo,bar.html", "attachment", "mime: invalid media parameter"},424 {"attachment; ;filename=foo", "attachment", "mime: invalid media parameter"},425 {"attachment; filename=foo bar.html", "attachment", "mime: invalid media parameter"},426 {`attachment; filename="foo.html"; filename="bar.html"`, "attachment", "mime: duplicate parameter name"},427 {"attachment; filename=foo[1](2).html", "attachment", "mime: invalid media parameter"},428 {"attachment; filename=foo-ä.html", "attachment", "mime: invalid media parameter"},429 {"attachment; filename=foo-ä.html", "attachment", "mime: invalid media parameter"},430 {`attachment; filename *=UTF-8''foo-%c3%a4.html`, "attachment", "mime: invalid media parameter"},431}432func TestParseMediaTypeBogus(t *testing.T) {433 for _, tt := range badMediaTypeTests {434 mt, params, err := ParseMediaType(tt.in)435 if err == nil {436 t.Errorf("ParseMediaType(%q) = nil error; want parse error", tt.in)437 continue438 }439 if err.Error() != tt.err {440 t.Errorf("ParseMediaType(%q) = err %q; want %q", tt.in, err.Error(), tt.err)441 }442 if params != nil {443 t.Errorf("ParseMediaType(%q): got non-nil params on error", tt.in)444 }445 if err != ErrInvalidMediaParameter && mt != "" {446 t.Errorf("ParseMediaType(%q): got unexpected non-empty media type string", tt.in)447 }448 if err == ErrInvalidMediaParameter && mt != tt.mt {449 t.Errorf("ParseMediaType(%q): in case of invalid parameters: expected type %q, got %q", tt.in, tt.mt, mt)450 }451 }452}453type formatTest struct {454 typ string455 params map[string]string456 want string457}458var formatTests = []formatTest{459 {"noslash", map[string]string{"X": "Y"}, "noslash; x=Y"}, // e.g. Content-Disposition values (RFC 2183); issue 11289460 {"foo bar/baz", nil, ""},461 {"foo/bar baz", nil, ""},462 {"attachment", map[string]string{"filename": "ÄÄŽŽÄÄÅ Å "}, "attachment; filename*=utf-8''%C4%84%C4%84%C5%BD%C5%BD%C4%8C%C4%8C%C5%A0%C5%A0"},463 {"attachment", map[string]string{"filename": "ÃÃÃÃÃÃÃÃ"}, "attachment; filename*=utf-8''%C3%81%C3%81%C3%8A%C3%8A%C3%87%C3%87%C3%8E%C3%8E"},464 {"attachment", map[string]string{"filename": "æ°æ®ç»è®¡.png"}, "attachment; filename*=utf-8''%E6%95%B0%E6%8D%AE%E7%BB%9F%E8%AE%A1.png"},465 {"foo/BAR", nil, "foo/bar"},466 {"foo/BAR", map[string]string{"X": "Y"}, "foo/bar; x=Y"},467 {"foo/BAR", map[string]string{"space": "With space"}, `foo/bar; space="With space"`},468 {"foo/BAR", map[string]string{"quote": `With "quote`}, `foo/bar; quote="With \"quote"`},469 {"foo/BAR", map[string]string{"bslash": `With \backslash`}, `foo/bar; bslash="With \\backslash"`},470 {"foo/BAR", map[string]string{"both": `With \backslash and "quote`}, `foo/bar; both="With \\backslash and \"quote"`},471 {"foo/BAR", map[string]string{"": "empty attribute"}, ""},472 {"foo/BAR", map[string]string{"bad attribute": "baz"}, ""},473 {"foo/BAR", map[string]string{"nonascii": "not an ascii character: ä"}, "foo/bar; nonascii*=utf-8''not%20an%20ascii%20character%3A%20%C3%A4"},474 {"foo/BAR", map[string]string{"ctl": "newline: \n nil: \000"}, "foo/bar; ctl*=utf-8''newline%3A%20%0A%20nil%3A%20%00"},475 {"foo/bar", map[string]string{"a": "av", "b": "bv", "c": "cv"}, "foo/bar; a=av; b=bv; c=cv"},476 {"foo/bar", map[string]string{"0": "'", "9": "'"}, "foo/bar; 0='; 9='"},477 {"foo", map[string]string{"bar": ""}, `foo; bar=""`},478}479func TestFormatMediaType(t *testing.T) {480 for i, tt := range formatTests {481 got := FormatMediaType(tt.typ, tt.params)482 if got != tt.want {483 t.Errorf("%d. FormatMediaType(%q, %v) = %q; want %q", i, tt.typ, tt.params, got, tt.want)484 }485 if got == "" {486 continue487 }488 typ, params, err := ParseMediaType(got)489 if err != nil {490 t.Errorf("%d. ParseMediaType(%q) err: %v", i, got, err)491 }492 if typ != strings.ToLower(tt.typ) {493 t.Errorf("%d. ParseMediaType(%q) typ = %q; want %q", i, got, typ, tt.typ)494 }495 for k, v := range tt.params {496 k = strings.ToLower(k)497 if params[k] != v {498 t.Errorf("%d. ParseMediaType(%q) params[%s] = %q; want %q", i, got, k, params[k], v)499 }500 }501 }502}...
appsearch.go
Source:appsearch.go
...9)10type AppSearch struct {11 functions.Templates12 mapSearchCache map[string]interface{}13 pageMap map[string]interface{}14}15func (this *AppSearch) Process(httpRes http.ResponseWriter, httpReq *http.Request, curdb database.Database) {16 httpRes.Header().Set("content-type", "application/json")17 if httpReq.Method != "POST" {18 http.Redirect(httpRes, httpReq, "/", http.StatusMovedPermanently)19 }20 GOSESSID, _ := httpReq.Cookie(_COOKIE_)21 this.mapSearchCache = curdb.GetSession(GOSESSID.Value, "mapSearchCache")22 if this.mapSearchCache == nil {23 this.mapSearchCache = make(map[string]interface{})24 }25 switch httpReq.FormValue("action") {26 default:27 fallthrough28 case "":29 this.pageMap = make(map[string]interface{})30 this.pageMap["app-searchdiv"] = this.search("subcategory", httpReq.FormValue("category"), curdb)31 // searchSubCategory32 searchSubCategory := ``33 // if this.mapSearchCache["category"] != nil && this.mapSearchCache["subcategory"] != nil {34 if this.mapSearchCache["category"] != nil {35 searchSubCategoryMap := this.search("keyword", this.mapSearchCache["category"].(string), curdb)36 searchSubCategory = `,"appSearchSubCategory":` + strconv.Quote(string(this.Generate(searchSubCategoryMap, nil)))37 }38 // searchSubCategory39 // searchKeyword40 searchKeyword := ``41 if this.mapSearchCache["subcategory"] != nil && this.mapSearchCache["keyword"] != nil {42 searchKeywordMap := this.search("end", this.mapSearchCache["subcategory"].(string), curdb)43 searchKeyword = `,"appSearchKeyword":` + strconv.Quote(string(this.Generate(searchKeywordMap, nil)))44 }45 // searchKeyword46 contentHTML := strconv.Quote(string(this.Generate(this.pageMap, nil)))47 searchTagsHTML := strconv.Quote(string(this.Generate(this.searchTags(), nil)))48 httpRes.Write([]byte(`{"appSearchDiv":` + contentHTML + `,"appSearchTags":` + searchTagsHTML + searchSubCategory + searchKeyword + `}`))49 return50 case "slider":51 switch functions.TrimEscape(httpReq.FormValue("type")) {52 default:53 delete(this.mapSearchCache, "type")54 case "PERKS":55 this.mapSearchCache["type"] = "Perk"56 case "PRIVILEGES":57 this.mapSearchCache["type"] = "Privilege"58 case "LIFESTYLE":59 this.mapSearchCache["type"] = "Lifestyle"60 case "LITE":61 this.mapSearchCache["type"] = "Lite"62 }63 curdb.SetSession(GOSESSID.Value, "mapSearchCache", this.mapSearchCache, false)64 httpRes.Write([]byte(`{"triggerAppSearch":"triggerAppSearch"}`))65 return66 case "category":67 searchResult := this.search("subcategory", httpReq.FormValue("category"), curdb)68 contentHTML := strconv.Quote(string(this.Generate(searchResult, nil)))69 searchTagsHTML := strconv.Quote(string(this.Generate(this.searchTags(), nil)))70 httpRes.Write([]byte(`{"appSearchCategory":` + contentHTML + `,"appSearchSubCategory":"","appSearchKeyword":""71 ,"ppSearchTags":` + searchTagsHTML + `,"triggerAppSearch":"triggerAppSearch"}`))72 return73 case "subcategory":74 //Populate SearchTags75 delete(this.mapSearchCache, "keyword")76 delete(this.mapSearchCache, "keywordtitle")77 delete(this.mapSearchCache, "subcategory")78 delete(this.mapSearchCache, "subcategorytitle")79 delete(this.mapSearchCache, "category")80 delete(this.mapSearchCache, "categorytitle")81 this.mapSearchCache["category"] = httpReq.FormValue("category")82 sql := fmt.Sprintf(`select title from category where control = '%s'`, this.mapSearchCache["category"])83 defaultMap, _ := curdb.Query(sql)84 if defaultMap["1"] != nil {85 this.mapSearchCache["categorytitle"] = defaultMap["1"].(map[string]interface{})["title"]86 }87 curdb.SetSession(GOSESSID.Value, "mapSearchCache", this.mapSearchCache, false)88 //Populate SearchTags89 searchResult := this.search("keyword", httpReq.FormValue("category"), curdb)90 contentHTML := strconv.Quote(string(this.Generate(searchResult, nil)))91 searchTagsHTML := strconv.Quote(string(this.Generate(this.searchTags(), nil)))92 httpRes.Write([]byte(`{"appSearchSubCategory":` + contentHTML + `,"appSearchKeyword":"","appSearchTags":` + searchTagsHTML + `,"triggerAppSearch":"triggerAppSearch"}`))93 //httpRes.Write([]byte(`{"appSearchSubCategory":` + contentHTML + `,"appSearchKeyword":"","appSearchTags":` + searchTagsHTML + `}`))94 case "keyword":95 //Populate SearchTags96 delete(this.mapSearchCache, "keyword")97 delete(this.mapSearchCache, "keywordtitle")98 delete(this.mapSearchCache, "subcategory")99 delete(this.mapSearchCache, "subcategorytitle")100 this.mapSearchCache["subcategory"] = httpReq.FormValue("category")101 sql := fmt.Sprintf(`select title from category where control = '%s'`, this.mapSearchCache["subcategory"])102 defaultMap, _ := curdb.Query(sql)103 if defaultMap["1"] != nil {104 this.mapSearchCache["subcategorytitle"] = defaultMap["1"].(map[string]interface{})["title"]105 }106 curdb.SetSession(GOSESSID.Value, "mapSearchCache", this.mapSearchCache, false)107 //Populate SearchTags108 searchResult := this.search("end", httpReq.FormValue("category"), curdb)109 contentHTML := strconv.Quote(string(this.Generate(searchResult, nil)))110 searchTagsHTML := strconv.Quote(string(this.Generate(this.searchTags(), nil)))111 httpRes.Write([]byte(`{"appSearchKeyword":` + contentHTML + `,"appSearchTags":` + searchTagsHTML + `,"triggerAppSearch":"triggerAppSearch"}`))112 //httpRes.Write([]byte(`{"appSearchKeyword":` + contentHTML + `,"appSearchTags":` + searchTagsHTML + `}`))113 return114 case "end":115 //Populate SearchTags116 delete(this.mapSearchCache, "keyword")117 delete(this.mapSearchCache, "keywordtitle")118 this.mapSearchCache["keyword"] = httpReq.FormValue("category")119 sql := fmt.Sprintf(`select title from category where control = '%s'`, this.mapSearchCache["keyword"])120 defaultMap, _ := curdb.Query(sql)121 if defaultMap["1"] != nil {122 this.mapSearchCache["keywordtitle"] = defaultMap["1"].(map[string]interface{})["title"]123 }124 curdb.SetSession(GOSESSID.Value, "mapSearchCache", this.mapSearchCache, false)125 //Populate SearchTags126 searchTagsHTML := strconv.Quote(string(this.Generate(this.searchTags(), nil)))127 httpRes.Write([]byte(`{"appSearchTags":` + searchTagsHTML + `,"triggerAppSearch":"triggerAppSearch"}`))128 //httpRes.Write([]byte(`{"appSearchTags":` + searchTagsHTML + `}`))129 return130 case "clearTagCategory":131 delete(this.mapSearchCache, "keyword")132 delete(this.mapSearchCache, "keywordtitle")133 delete(this.mapSearchCache, "subcategory")134 delete(this.mapSearchCache, "subcategorytitle")135 delete(this.mapSearchCache, "category")136 delete(this.mapSearchCache, "categorytitle")...
Map
Using AI Code Generation
1import (2func main() {3 doc, err := html.Parse(os.Stdin)4 if err != nil {5 fmt.Fprintf(os.Stderr, "findlinks1: %v6 os.Exit(1)7 }8 for _, link := range visit(nil, doc) {9 fmt.Println(link)10 }11}12func visit(links []string, n *html.Node) []string {13 if n.Type == html.ElementNode && n.Data == "a" {14 for _, a := range n.Attr {15 if a.Key == "href" {16 links = append(links, a.Val)17 }18 }19 }20 for c := n.FirstChild; c != nil; c = c.NextSibling {21 links = visit(links, c)22 }23}24import (25func main() {26 doc, err := html.Parse(os.Stdin)27 if err != nil {28 fmt.Fprintf(os.Stderr, "findlinks2: %v29 os.Exit(1)30 }31 for _, link := range visit(nil, doc) {32 fmt.Println(link)33 }34}35func visit(links []string, n *html.Node) []string {36 if n.Type == html.ElementNode && n.Data == "a" {37 for _, a := range n.Attr {38 if a.Key == "href" {39 links = append(links, a.Val)40 }41 }42 }43 for c := n.FirstChild; c != nil; c = c.NextSibling {44 links = visit(links, c)45 }46}47import (48func main() {49 doc, err := html.Parse(os.Stdin)50 if err != nil {51 fmt.Fprintf(os.Stderr, "findlinks3: %v52 os.Exit(1)53 }54 for _, link := range visit(nil, doc) {55 fmt.Println(link)56 }57}58func visit(links
Map
Using AI Code Generation
1import (2func main() {3 doc, err := html.Parse(os.Stdin)4 if err != nil {5 fmt.Fprintf(os.Stderr, "findlinks1: %v6 os.Exit(1)7 }8 for _, link := range visit(nil, doc) {9 fmt.Println(link)10 }11}12func visit(links []string, n *html.Node) []string {13 if n.Type == html.ElementNode && n.Data == "a" {14 for _, a := range n.Attr {15 if a.Key == "href" {16 links = append(links, a.Val)17 }18 }19 }20 for c := n.FirstChild; c != nil; c = c.NextSibling {21 links = visit(links, c)22 }23}24import (25func main() {26 doc, err := html.Parse(os.Stdin)27 if err != nil {28 fmt.Fprintf(os.Stderr, "findlinks2: %v29 os.Exit(1)30 }31 for _, link := range visit(nil, doc) {32 fmt.Println(link)33 }34}35func visit(links []string, n *html.Node) []string {36 forEachNode(n, func(n *html.Node) {37 if n.Type == html.ElementNode && n.Data == "a" {38 for _, a := range n.Attr {39 if a.Key == "href" {40 links = append(links, a.Val)41 }42 }43 }44 }, nil)45}46func forEachNode(n *html.Node, pre, post func(n *html.Node)) {47 if pre != nil {48 pre(n)49 }50 for c := n.FirstChild; c != nil; c = c.NextSibling {51 forEachNode(c, pre, post)52 }53 if post != nil {54 post(n)55 }56}57import (58func main() {59 doc, err := html.Parse(os.Stdin)60 if err != nil {
Map
Using AI Code Generation
1import (2func main() {3 if err != nil {4 log.Fatal(err)5 }6 body, err := ioutil.ReadAll(resp.Body)7 if err != nil {8 log.Fatal(err)9 }10 s := string(body)11 words := strings.Fields(s)12 m := make(map[string]int)13 for _, word := range words {14 }15 for k, v := range m {16 fmt.Println(k, v)17 if i > 10 {18 }19 }20}21import (22func main() {23 if err != nil {24 log.Fatal(err)25 }26 body, err := ioutil.ReadAll(resp.Body)27 if err != nil {28 log.Fatal(err)29 }30 s := string(body)31 words := strings.Fields(s)32 m := make(map[string]int)33 for _, word := range words {34 }35 for k, v := range m {
Map
Using AI Code Generation
1import (2func main() {3 defer resp.Body.Close()4 body, _ := ioutil.ReadAll(resp.Body)5 fmt.Println(strings.Map(func(r rune) rune {6 if r == 'o' {7 }8 }, string(body)))9}10import (11func main() {12 fmt.Println(strings.Map(func(r rune) rune {13 if r == 'o' {14 }15 }, "Google.com"))16}17import (18func main() {19 fmt.Println(strings.Map(func(r rune) rune {20 if r == 'o' {21 }22 }, "Google.com"))23}24import (25func main() {26 fmt.Println(strings.Map(func(r rune) rune {27 if r == 'o' {28 }29 }, "Google.com"))30}31import (32func main() {33 fmt.Println(strings.Map(func(r rune) rune {34 if r == 'o' {35 }36 }, "Google.com"))37}38import (39func main() {40 fmt.Println(strings.Map(func(r rune) rune {41 if r == 'o' {42 }43 }, "Google.com"))44}
Map
Using AI Code Generation
1import (2func main() {3 if err != nil {4 log.Fatal(err)5 }6 defer resp.Body.Close()7 body, err := ioutil.ReadAll(resp.Body)8 if err != nil {9 log.Fatal(err)10 }11 doc, err := html.Parse(strings.NewReader(string(body)))12 if err != nil {13 log.Fatal(err)14 }15 fmt.Println(doc.FirstChild.Data)16}17import (18func main() {19 if err != nil {20 log.Fatal(err)21 }22 defer resp.Body.Close()23 body, err := ioutil.ReadAll(resp.Body)24 if err != nil {25 log.Fatal(err)26 }27 doc, err := html.Parse(strings.NewReader(string(body)))28 if err != nil {29 log.Fatal(err)30 }31 fmt.Println(doc.Data)32}33import (34func main() {35 if err != nil {36 log.Fatal(err)37 }38 defer resp.Body.Close()39 body, err := ioutil.ReadAll(resp.Body)40 if err != nil {41 log.Fatal(err)42 }43 doc, err := html.Parse(strings.NewReader(string(body)))44 if err != nil {45 log.Fatal(err)46 }47 fmt.Println(doc.FirstChild.FirstChild.Data)48}49import (50func main() {
Map
Using AI Code Generation
1import (2func main() {3 for _, url := range os.Args[1:] {4 resp, err := http.Get(url)5 if err != nil {6 fmt.Fprintf(os.Stderr, "fetch: %v7 os.Exit(1)8 }9 doc, err := html.Parse(resp.Body)10 resp.Body.Close()11 if err != nil {12 fmt.Fprintf(os.Stderr, "findlinks1: %v13 os.Exit(1)14 }15 for _, link := range visit(nil, doc) {16 fmt.Println(link)17 }18 }19}20func visit(links []string, n *html.Node) []string {21 if n.Type == html.ElementNode && n.Data == "a" {22 for _, a := range n.Attr {23 if a.Key == "href" {24 links = append(links, a.Val)25 }26 }27 }28 for c := n.FirstChild; c != nil; c = c.NextSibling {29 links = visit(links, c)30 }31}
Map
Using AI Code Generation
1import (2func main() {3 if err != nil {4 fmt.Println(err)5 }6 defer resp.Body.Close()7 doc, err := html.Parse(resp.Body)8 if err != nil {9 fmt.Println(err)10 }11 var f func(*html.Node)12 f = func(n *html.Node) {13 if n.Type == html.ElementNode && n.Data == "a" {14 for _, a := range n.Attr {15 if a.Key == "href" {16 fmt.Println(a.Val)17 }18 }19 }20 for c := n.FirstChild; c != nil; c = c.NextSibling {21 f(c)22 }23 }24 f(doc)25}
Map
Using AI Code Generation
1import (2func main() {3 if err != nil {4 fmt.Printf("%s", err)5 } else {6 defer response.Body.Close()7 contents, err := ioutil.ReadAll(response.Body)8 if err != nil {9 fmt.Printf("%s", err)10 }11 fmt.Printf("%s12", string(contents))13 }14}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!