Best K6 code snippet using html.CrossOrigin
elements_gen_test.go
Source:elements_gen_test.go
1package html2import (3 "context"4 "testing"5 "github.com/dop251/goja"6 "github.com/luckybroman5/http-log-reconstructor/k6/js/common"7 "github.com/stretchr/testify/assert"8)9var textTests = []struct {10 id string11 property string12 data string13}{14 {"a1", "download", "file:///path/name"},15 {"a1", "referrerPolicy", "no-referrer"},16 {"a1", "href", "http://test.url"},17 {"a1", "target", "__blank"},18 {"a1", "type", "text/html"},19 {"a1", "accessKey", "w"},20 {"a1", "hrefLang", "es"},21 {"a1", "toString", "http://test.url"},22 {"a2", "referrerPolicy", ""},23 {"a2", "accessKey", ""},24 {"audio1", "src", "foo.wav"},25 {"audio1", "crossOrigin", "anonymous"},26 {"audio1", "currentSrc", "foo.wav"},27 {"audio1", "mediaGroup", "testgroup"},28 {"base1", "href", "foo.html"},29 {"base1", "target", "__any"},30 {"btn1", "accessKey", "e"},31 {"btn1", "type", "button"},32 {"btn2", "type", "submit"},33 {"btn3", "type", "submit"},34 {"data1", "value", "121"},35 {"data2", "value", ""},36 {"embed1", "type", "video/avi"},37 {"embed1", "src", "movie.avi"},38 {"embed1", "width", "640"},39 {"embed1", "height", "480"},40 {"fset1", "name", "fset1_name"},41 {"form1", "target", "__self"},42 {"form1", "action", "submit_url"},43 {"form1", "enctype", "text/plain"},44 {"form1", "encoding", "text/plain"},45 {"form1", "acceptCharset", "ISO-8859-1"},46 {"form1", "target", "__self"},47 {"form1", "autocomplete", "off"},48 {"form2", "enctype", "application/x-www-form-urlencoded"},49 {"form2", "autocomplete", "on"},50 {"iframe1", "referrerPolicy", "no-referrer"},51 {"iframe2", "referrerPolicy", ""},52 {"iframe3", "referrerPolicy", ""},53 {"iframe1", "width", "640"},54 {"iframe1", "height", "480"},55 {"iframe1", "name", "frame_name"},56 {"iframe1", "src", "testframe.html"},57 {"img1", "src", "test.png"},58 {"img1", "currentSrc", "test.png"},59 {"img1", "sizes", "100vw,50vw"},60 {"img1", "srcset", "large.jpg 1024w,medium.jpg 640w"},61 {"img1", "alt", "alt text"},62 {"img1", "crossOrigin", "anonymous"},63 {"img1", "name", "img_name"},64 {"img1", "useMap", "#map_name"},65 {"img1", "referrerPolicy", "origin"},66 {"img2", "crossOrigin", "use-credentials"},67 {"img2", "referrerPolicy", ""},68 {"img3", "referrerPolicy", ""},69 {"input1", "name", "input1_name"},70 {"input1", "type", "button"},71 {"input1", "value", "input1-val"},72 {"input1", "defaultValue", "input1-val"},73 {"input2", "type", "text"},74 {"input2", "value", ""},75 {"input5", "alt", "input_img"},76 {"input5", "src", "input.png"},77 {"input5", "width", "80"},78 {"input5", "height", "40"},79 {"input6", "accept", ".jpg,.png"},80 {"input7", "autocomplete", "off"},81 {"input7", "pattern", "..."},82 {"input7", "placeholder", "help text"},83 {"input7", "min", "2017-01-01"},84 {"input7", "max", "2017-12-12"},85 {"input7", "dirName", "input7.dir"},86 {"input7", "accessKey", "s"},87 {"input7", "step", "0.1"},88 {"kg1", "challenge", "cx1"},89 {"kg1", "keytype", "DSA"},90 {"kg1", "name", "kg1_name"},91 {"kg2", "challenge", ""},92 {"kg2", "keytype", "RSA"},93 {"kg2", "type", "keygen"},94 {"label1", "htmlFor", "input1_name"},95 {"legend1", "accessKey", "l"},96 {"li1", "type", "disc"},97 {"li2", "type", ""},98 {"link1", "crossOrigin", "use-credentials"},99 {"link1", "referrerPolicy", "no-referrer"},100 {"link1", "href", "test.css"},101 {"link1", "hreflang", "pl"},102 {"link1", "media", "print"},103 {"link1", "rel", "alternate author"},104 {"link1", "target", "__self"},105 {"link1", "type", "stylesheet"},106 {"link2", "referrerPolicy", ""},107 {"map1", "name", "map1_name"},108 {"meta1", "name", "author"},109 {"meta1", "content", "author name"},110 {"meta2", "httpEquiv", "refresh"},111 {"meta2", "content", "1;www.test.com"},112 {"meta2", "content", "1;www.test.com"},113 {"ins1", "cite", "cite.html"},114 {"ins1", "datetime", "2017-01-01"},115 {"object1", "data", "test.png"},116 {"object1", "type", "image/png"},117 {"object1", "name", "obj1_name"},118 {"object1", "width", "150"},119 {"object1", "height", "75"},120 {"object1", "useMap", "#map1_name"},121 {"ol1", "type", "a"},122 {"optgroup1", "label", "optlabel"},123 {"out1", "htmlFor", "input1"},124 {"out1", "name", "out1_name"},125 {"out1", "type", "output"},126 {"par1", "name", "param1_name"},127 {"par1", "value", "param1_val"},128 {"pre1", "name", "pre1_name"},129 {"pre1", "value", "pre1_val"},130 {"quote1", "cite", "http://cite.com/url"},131 {"script1", "crossOrigin", "use-credentials"},132 {"script1", "type", "text/javascript"},133 {"script1", "src", "script.js"},134 {"script1", "charset", "ISO-8859-1"},135 {"select1", "name", "sel1_name"},136 {"src1", "keySystem", "keysys"},137 {"src1", "media", "(min-width: 600px)"},138 {"src1", "sizes", "100vw,50vw"},139 {"src1", "srcset", "large.jpg 1024w,medium.jpg 640w"},140 {"src1", "src", "test.png"},141 {"src1", "type", "image/png"},142 {"td1", "headers", "th1"},143 {"th1", "abbr", "hdr"},144 {"th1", "scope", "row"},145 {"txtarea1", "accessKey", "k"},146 {"txtarea1", "autocomplete", "off"},147 {"txtarea1", "autocapitalize", "words"},148 {"txtarea1", "wrap", "hard"},149 {"txtarea2", "autocomplete", "on"},150 {"txtarea2", "autocapitalize", "sentences"},151 {"txtarea2", "wrap", "soft"},152 {"track1", "kind", "metadata"},153 {"track1", "src", "foo.en.vtt"},154 {"track1", "label", "English"},155 {"track1", "srclang", "en"},156 {"track2", "kind", "subtitle"},157 {"track2", "src", "foo.sv.vtt"},158 {"track2", "srclang", "sv"},159 {"track2", "label", "Svenska"},160 {"time1", "datetime", "2017-01-01"},161 {"ul1", "type", "circle"},162}163var intTests = []struct {164 id string165 property string166 data int167}{168 {"img1", "width", 100},169 {"img1", "height", 50},170 {"input7", "maxLength", 10},171 {"input7", "size", 5},172 {"li1", "value", 0},173 {"li2", "value", 10},174 {"meter1", "min", 90},175 {"meter1", "max", 110},176 {"meter1", "low", 95},177 {"meter1", "high", 105},178 {"meter1", "optimum", 100},179 {"object1", "tabIndex", 6},180 {"ol1", "start", 1},181 {"td1", "colSpan", 2},182 {"td1", "rowSpan", 3},183 {"th1", "colSpan", 1},184 {"th1", "colSpan", 1},185 {"txtarea1", "rows", 10},186 {"txtarea1", "cols", 12},187 {"txtarea1", "maxLength", 128},188 {"txtarea1", "tabIndex", 4},189}190var boolTests = []struct {191 idTrue string192 idFalse string193 property string194}{195 {"audio1", "audio2", "autoplay"},196 {"audio1", "audio2", "controls"},197 {"audio1", "audio2", "loop"},198 {"audio1", "audio2", "muted"},199 {"audio1", "audio2", "defaultMuted"},200 {"btn1", "btn2", "autofocus"},201 {"btn1", "btn2", "disabled"},202 {"fset1", "fset2", "disabled"},203 {"form1", "form2", "noValidate"},204 {"iframe1", "iframe2", "allowfullscreen"},205 {"img1", "img2", "isMap"},206 {"input1", "input2", "disabled"},207 {"input1", "input2", "autofocus"},208 {"input1", "input2", "required"},209 {"input3", "input4", "checked"},210 {"input3", "input4", "defaultChecked"},211 {"input7", "input1", "readonly"},212 {"input3", "input4", "multiple"},213 {"kg1", "kg2", "autofocus"},214 {"kg1", "kg2", "disabled"},215 {"object1", "object2", "typeMustMatch"},216 {"ol1", "ol2", "reversed"},217 {"optgroup1", "optgroup2", "disabled"},218 {"opt1", "opt2", "selected"},219 {"opt1", "opt2", "defaultSelected"},220 {"script1", "script2", "async"},221 {"script1", "script2", "defer"},222 {"script1", "script2", "noModule"},223 {"select1", "select2", "autofocus"},224 {"select1", "select2", "disabled"},225 {"select1", "select2", "multiple"},226 {"select1", "select2", "required"},227 {"table1", "table2", "sortable"},228 {"th1", "th2", "sorted"},229 {"txtarea1", "txtarea2", "readOnly"},230 {"txtarea1", "txtarea2", "required"},231}232var nullTests = []struct {233 id string234 property string235}{236 {"audio2", "crossOrigin"},237 {"img3", "crossOrigin"},238 {"link2", "crossOrigin"},239}240var urlTests = []struct {241 id string242 property string243 baseUrl string244 data string245}{246 {"a2", "href", "http://example.com/testpath", ""},247 {"a3", "href", "http://example.com", "http://example.com/relpath"},248 {"a3", "href", "http://example.com/somepath", "http://example.com/relpath"},249 {"a3", "href", "http://example.com/subdir/", "http://example.com/subdir/relpath"},250 {"a4", "href", "http://example.com/", "http://example.com/abspath"},251 {"a4", "href", "http://example.com/subdir/", "http://example.com/abspath"},252 {"a5", "href", "http://example.com/path?a=no-a&c=no-c", "http://example.com/path?a=yes-a&b=yes-b"},253 {"a6", "href", "http://example.com/path#oldfrag", "http://example.com/path#testfrag"},254 {"a7", "href", "http://example.com/prevdir/prevpath", "http://example.com/prtpath"},255 {"a8", "href", "http://example.com/testpath", "http://example.com/testpath"},256 {"base1", "href", "http://example.com", "http://example.com/foo.html"},257 {"base2", "href", "http://example.com", "http://example.com"},258 {"base3", "href", "http://example.com", "http://example.com"},259 {"audio1", "src", "http://example.com", "http://example.com/foo.wav"},260 {"audio2", "src", "http://example.com", ""},261 {"audio3", "src", "http://example.com", "http://example.com"},262 {"form1", "action", "http://example.com/", "http://example.com/submit_url"},263 {"form2", "action", "http://example.com/", ""},264 {"form3", "action", "http://example.com/", "http://example.com/"},265 {"iframe1", "src", "http://example.com", "http://example.com/testframe.html"},266 {"iframe2", "src", "http://example.com", ""},267 {"iframe3", "src", "http://example.com", "http://example.com"},268 {"img1", "src", "http://example.com", "http://example.com/test.png"},269 {"img2", "src", "http://example.com", ""},270 {"img3", "src", "http://example.com", "http://example.com"},271 {"input5", "src", "http://example.com", "http://example.com/input.png"},272 {"input5b", "src", "http://example.com", ""},273 {"input5c", "src", "http://example.com", "http://example.com"},274 {"link1", "href", "http://example.com", "http://example.com/test.css"},275 {"link2", "href", "http://example.com", ""},276 {"link3", "href", "http://example.com", "http://example.com"},277 {"object1", "data", "http://example.com", "http://example.com/test.png"},278 {"object2", "data", "http://example.com", ""},279 {"object3", "data", "http://example.com", "http://example.com"},280 {"script1", "src", "http://example.com", "http://example.com/script.js"},281 {"script2", "src", "http://example.com", ""},282 {"script3", "src", "http://example.com", "http://example.com"},283 {"src1", "src", "http://example.com", "http://example.com/test.png"},284 {"src2", "src", "http://example.com", ""},285 {"src3", "src", "http://example.com", "http://example.com"},286 {"track1", "src", "http://example.com", "http://example.com/foo.en.vtt"},287 {"track3", "src", "http://example.com", ""},288 {"track4", "src", "http://example.com", "http://example.com"},289}290const testGenElems = `<html><body>291 <a id="a1" download="file:///path/name" referrerpolicy="no-referrer" rel="open" href="http://test.url" target="__blank" type="text/html" accesskey="w" hreflang="es"></a> 292 <a id="a2"></a>293 <a id="a3" href="relpath"></a>294 <a id="a4" href="/abspath"></a>295 <a id="a5" href="?a=yes-a&b=yes-b"></a>296 <a id="a6" href="#testfrag"></a>297 <a id="a7" href="../prtpath"></a>298 <a id="a8" href=""></a>299 <audio id="audio1" autoplay controls loop muted src="foo.wav" crossorigin="anonymous" mediagroup="testgroup"></audio>300 <audio id="audio2"></audio>301 <audio id="audio3" src=""></audio>302 <base id="base1" href="foo.html" target="__any"></base>303 <base id="base2"></base>304 <base id="base3" href="" target="__any"></base>305 <button id="btn1" accesskey="e" target="__any" autofocus disabled type="button"></button>306 <button id="btn2"></button>307 <button id="btn3" type="invalid_uses_default"></button> <button id="btn3" type="invalid_uses_default"></button>308 <ul><li><data id="data1" value="121"></data></li><li><data id="data2"></data></li></ul>309 <embed id="embed1" type="video/avi" src="movie.avi" width="640" height="480">310 <fieldset id="fset1" disabled name="fset1_name"></fieldset>311 <fieldset id="fset2"></fieldset>312 <form id="form1" name="form1_name" target="__self" enctype="text/plain" action="submit_url" accept-charset="ISO-8859-1" autocomplete="off" novalidate></form>313 <form id="form2"></form>314 <form id="form3" action=""></form>315 <iframe id="iframe1" allowfullscreen referrerpolicy="no-referrer" name="frame_name" width="640" height="480" src="testframe.html"></iframe>316 <iframe id="iframe2" referrerpolicy="use-default-when-invalid"></iframe>317 <iframe id="iframe3" src=""></iframe>318 <img id="img1" src="test.png" sizes="100vw,50vw" srcset="large.jpg 1024w,medium.jpg 640w" alt="alt text" crossorigin="anonymous" height="50" width="100" ismap name="img_name" usemap="#map_name" referrerpolicy="origin"/>319 <img id="img2" crossorigin="use-credentials" referrerpolicy="use-default-when-invalid"/>320 <img id="img3" src=""/>321 <input id="input1" name="input1_name" disabled autofocus required value="input1-val" type="button"/>322 <input id="input2"/>323 <input id="input3" type="checkbox" checked multiple/>324 <input id="input4" type="checkbox"/>325 <input id="input5" type="image" alt="input_img" src="input.png" width="80" height="40"/>326 <input id="input5b" type="image" />327 <input id="input5c" type="image" src=""/>328 <input id="input6" type="file" accept=".jpg,.png"/>329 <input id="input7" type="text" autocomplete="off" maxlength="10" size="5" pattern="..." placeholder="help text" readonly min="2017-01-01" max="2017-12-12" dirname="input7.dir" accesskey="s" step="0.1"/>330 <keygen id="kg1" autofocus challenge="cx1" disabled keytype="DSA" name="kg1_name"/>331 <keygen id="kg2"/>332 <label id="label1" for="input1_name"/>333 <legend id="legend1" accesskey="l"/>334 <li id="li1" type="disc"></li> <li id="li2" value="10" type=""></li>335 <link id="link1" crossorigin="use-credentials" referrerpolicy="no-referrer" href="test.css" hreflang="pl" media="print" rel="alternate author" target="__self" type="stylesheet"/>336 <link id="link2"/>337 <link id="link3" href=""/>338 <map id="map1" name="map1_name"></map>339 <meta id="meta1" name="author" content="author name" />340 <meta id="meta2" http-equiv="refresh" content="1;www.test.com" />341 <meter id="meter1" min="90" max="110" low="95" high="105" optimum="100"/>342 <ins id="ins1" cite="cite.html" datetime="2017-01-01"/>343 <object id="object1" name="obj1_name" data="test.png" type="image/png" width="150" height="75" tabindex="6" typemustmatch usemap="#map1_name"/>344 <object id="object2"/>345 <object id="object3" data=""/>346 <ol id="ol1" reversed start="1" type="a"></ol> <ol id="ol2"></ol>347 <optgroup id="optgroup1" disabled label="optlabel"></optgroup>348 <optgroup id="optgroup2"></optgroup>349 <option id="opt1" selected/><option id="opt2" />350 <output id="out1" for="input1" name="out1_name"/>351 <param id="par1" name="param1_name" value="param1_val"/>352 <pre id="pre1" name="pre1_name" value="pre1_val"/>353 <quote id="quote1" cite="http://cite.com/url"/>354 <script id="script1" crossorigin="use-credentials" type="text/javascript" src="script.js" charset="ISO-8859-1" defer async nomodule></script>355 <script id="script2"></script>356 <script id="script3" src=""></script>357 <select id="select1" name="sel1_name" autofocus disabled multiple required></select>358 <select id="select2"></select>359 <source id="src1" keysystem="keysys" media="(min-width: 600px)" sizes="100vw,50vw" srcset="large.jpg 1024w,medium.jpg 640w" src="test.png" type="image/png"></source>360 <source id="src2"></source>361 <source id="src3" src=""></source>362 <style id="style1" media="print"></style>363 <table id="table1" sortable><tr><td id="td1" colspan="2" rowspan="3" headers="th1"></th><th id="th1" abbr="hdr" scope="row" sorted>Header</th><th id="th2"></th></tr></table>364 <table id="table2"></table>365 <textarea id="txtarea1" value="init_txt" placeholder="display_txt" rows="10" cols="12" maxlength="128" accesskey="k" tabIndex="4" readonly required autocomplete="off" autocapitalize="words" wrap="hard"></textarea>366 <textarea id="txtarea2"></textarea>367 <time id="time1" datetime="2017-01-01"/>368 <track id="track1" kind="metadata" src="foo.en.vtt" srclang="en" label="English"></track>369 <track id="track2" src="foo.sv.vtt" srclang="sv" label="Svenska"></track>370 <track id="track3"></track>371 <track id="track4" src=""></track>372 <ul id="ul1" type="circle"/>373 `374func TestGenElements(t *testing.T) {375 rt := goja.New()376 rt.SetFieldNameMapper(common.FieldNameMapper{})377 ctx := common.WithRuntime(context.Background(), rt)378 rt.Set("src", testGenElems)379 rt.Set("html", common.Bind(rt, &HTML{}, &ctx))380 _, err := common.RunString(rt, "let doc = html.parseHTML(src)")381 assert.NoError(t, err)382 assert.IsType(t, Selection{}, rt.Get("doc").Export())383 t.Run("Test text properties", func(t *testing.T) {384 for _, test := range textTests {385 v, err := common.RunString(rt, `doc.find("#`+test.id+`").get(0).`+test.property+`()`)386 if err != nil {387 t.Errorf("Error for property name '%s' on element id '#%s':\n%+v ", test.id, test.property, err)388 } else if v.Export() != test.data {389 t.Errorf("Expected '%s' for property name '%s' element id '#%s'. Got '%s'", test.data, test.property, test.id, v.String())390 }391 }392 })393 t.Run("Test bool properties", func(t *testing.T) {394 for _, test := range boolTests {395 vT, errT := common.RunString(rt, `doc.find("#`+test.idTrue+`").get(0).`+test.property+`()`)396 if errT != nil {397 t.Errorf("Error for property name '%s' on element id '#%s':\n%+v", test.property, test.idTrue, errT)398 } else if vT.Export() != true { // nolint: gosimple399 t.Errorf("Expected true for property name '%s' on element id '#%s'", test.property, test.idTrue)400 }401 vF, errF := common.RunString(rt, `doc.find("#`+test.idFalse+`").get(0).`+test.property+`()`)402 if errF != nil {403 t.Errorf("Error for property name '%s' on element id '#%s':\n%+v", test.property, test.idFalse, errF)404 } else if vF.Export() != false { // nolint: gosimple405 t.Errorf("Expected false for property name '%s' on element id '#%s'", test.property, test.idFalse)406 }407 }408 })409 t.Run("Test int64 properties", func(t *testing.T) {410 for _, test := range intTests {411 v, err := common.RunString(rt, `doc.find("#`+test.id+`").get(0).`+test.property+`()`)412 if err != nil {413 t.Errorf("Error for property name '%s' on element id '#%s':\n%+v", test.property, test.id, err)414 } else if v.Export() != int64(test.data) {415 t.Errorf("Expected %d for property name '%s' on element id '#%s'. Got %d", test.data, test.property, test.id, v.ToInteger())416 }417 }418 })419 t.Run("Test nullable properties", func(t *testing.T) {420 for _, test := range nullTests {421 v, err := common.RunString(rt, `doc.find("#`+test.id+`").get(0).`+test.property+`()`)422 if err != nil {423 t.Errorf("Error for property name '%s' on element id '#%s':\n%+v", test.property, test.id, err)424 } else if v.Export() != nil {425 t.Errorf("Expected null for property name '%s' on element id '#%s'", test.property, test.id)426 }427 }428 })429 t.Run("Test url properties", func(t *testing.T) {430 html := HTML{}431 sel, parseError := html.ParseHTML(ctx, testGenElems)432 if parseError != nil {433 t.Errorf("Unable to parse html")434 }435 for _, test := range urlTests {436 sel.URL = test.baseUrl437 rt.Set("urldoc", sel)438 v, err := common.RunString(rt, `urldoc.find("#`+test.id+`").get(0).`+test.property+`()`)439 if err != nil {440 t.Errorf("Error for url property '%s' on element id '#%s':\n%+v", test.property, test.id, err)441 } else if v.Export() != test.data {442 t.Errorf("Expected '%s' for property name '%s' on element id '#%s', got '%s'", test.data, test.property, test.id, v.String())443 }444 }445 })446}...
assets.go
Source:assets.go
1package assets2import (3 "time"4 "github.com/jessevdk/go-assets"5)6var _Assets9f0ae851af9adb08e3242917d7d52dc270c7bae2 = "<!DOCTYPE html>\n<html>\n{{template \"header\" .}}\n<body>\n\t<a href={{ .groupsUrl }}> ÐолÑÑиÑÑ ÑпиÑок гÑÑпп!\t</a>\n</body>\n</html>"7var _Assets363a2f90352d30e50b53cfc4ed83d226af0ef56a = "<!DOCTYPE html>\n<html>\n<script>\n\tvar fragment = window.location.hash;\n fragment = fragment.replace(\"#\", '?')\n window.location.href = '/groups' + fragment;\n</script>\n<body>\n</body>\n</html>"8var _Assetsc59dbd0327b9cc0f2cd2bc1b96e9e14612028e96 = "<!DOCTYPE html>\n<html>\n{{template \"header\" .}}\n<body>\n\t{{.list.Count}}\n\t<form action=\"/delete\" method=\"post\">\n\t\t<input name=\"token\" value=\"{{.token}}\" hidden>\n\t\t{{ range .list.Groups }}\n\t\t\t<p>\n\t\t\t\t<img src={{.Photo200}}><br>\n\t\t\t\t<input type=\"checkbox\" name=\"groups[]\" value=\"{{.Id}}\" id=\"{{.Id}}\" checked/>\n\t\t\t\t<span style=\"padding: 0px 20px;\"> </span>\n\t\t\t\t<a href=\"https://vk.com/club{{.Id}}\">{{.Name}}</a>\n\t\t\t</p>\n\t\t{{end}}\n\t\t<p><input type=\"submit\"></p>\n\t</form>\n</body>\n</html>"9var _Assets7c932e997237213be967a49691ce1726e11d3921 = "{{define \"header\"}}\n<head>\n <link rel=\"stylesheet\" href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css\"\n integrity=\"sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh\"\n crossorigin=\"anonymous\">\n <script src=\"https://code.jquery.com/jquery-3.4.1.slim.min.js\"\n integrity=\"sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n\"\n crossorigin=\"anonymous\"></script>\n <script src=\"https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js\"\n integrity=\"sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo\"\n crossorigin=\"anonymous\"></script>\n <script src=\"https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js\"\n integrity=\"sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6\"\n crossorigin=\"anonymous\"></script>\n</head>\n{{end}}"10// Assets returns go-assets FileSystem11var Assets = assets.NewFileSystem(map[string][]string{"/": []string{"templates"}, "/templates": []string{"index.html", "fragment.html", "groups.html", "headers.html"}}, map[string]*assets.File{12 "/templates/index.html": &assets.File{13 Path: "/templates/index.html",14 FileMode: 0x1b4,15 Mtime: time.Unix(1625917808, 1625917808331077955),16 Data: []byte(_Assets9f0ae851af9adb08e3242917d7d52dc270c7bae2),17 }, "/templates/fragment.html": &assets.File{18 Path: "/templates/fragment.html",19 FileMode: 0x1b4,20 Mtime: time.Unix(1625938374, 1625938374414255240),21 Data: []byte(_Assets363a2f90352d30e50b53cfc4ed83d226af0ef56a),22 }, "/templates/groups.html": &assets.File{23 Path: "/templates/groups.html",24 FileMode: 0x1b4,25 Mtime: time.Unix(1626004220, 1626004220377725121),26 Data: []byte(_Assetsc59dbd0327b9cc0f2cd2bc1b96e9e14612028e96),27 }, "/templates/headers.html": &assets.File{28 Path: "/templates/headers.html",29 FileMode: 0x1b4,30 Mtime: time.Unix(1625917731, 1625917731937953190),31 Data: []byte(_Assets7c932e997237213be967a49691ce1726e11d3921),32 }, "/": &assets.File{33 Path: "/",34 FileMode: 0x800001fd,35 Mtime: time.Unix(1625934021, 1625934021977756836),36 Data: nil,37 }, "/templates": &assets.File{38 Path: "/templates",39 FileMode: 0x800001fd,40 Mtime: time.Unix(1625991447, 1625991447036939477),41 Data: nil,42 }}, "")...
playground.go
Source:playground.go
1package playground2import (3 "html/template"4 "net/http"5)6var page = template.Must(template.New("graphiql").Parse(`<!DOCTYPE html>7<html>8<head>9 <meta charset=utf-8/>10 <meta name="viewport" content="user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui">11 <link rel="shortcut icon" href="https://graphcool-playground.netlify.com/favicon.png">12 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/graphql-playground-react@{{ .version }}/build/static/css/index.css"13 integrity="{{ .cssSRI }}" crossorigin="anonymous"/>14 <link rel="shortcut icon" href="https://cdn.jsdelivr.net/npm/graphql-playground-react@{{ .version }}/build/favicon.png"15 integrity="{{ .faviconSRI }}" crossorigin="anonymous"/>16 <script src="https://cdn.jsdelivr.net/npm/graphql-playground-react@{{ .version }}/build/static/js/middleware.js"17 integrity="{{ .jsSRI }}" crossorigin="anonymous"></script>18 <title>{{.title}}</title>19</head>20<body>21<style type="text/css">22 html { font-family: "Open Sans", sans-serif; overflow: hidden; }23 body { margin: 0; background: #172a3a; }24</style>25<div id="root"/>26<script type="text/javascript">27 window.addEventListener('load', function (event) {28 const root = document.getElementById('root');29 root.classList.add('playgroundIn');30 const wsProto = location.protocol == 'https:' ? 'wss:' : 'ws:'31 GraphQLPlayground.init(root, {32 endpoint: location.protocol + '//' + location.host + '{{.endpoint}}',33 subscriptionsEndpoint: wsProto + '//' + location.host + '{{.endpoint }}',34 shareEnabled: true,35 settings: {36 'request.credentials': 'same-origin'37 }38 })39 })40</script>41</body>42</html>43`))44func Handler(title string, endpoint string) http.HandlerFunc {45 return func(w http.ResponseWriter, r *http.Request) {46 w.Header().Add("Content-Type", "text/html")47 err := page.Execute(w, map[string]string{48 "title": title,49 "endpoint": endpoint,50 "version": "1.7.20",51 "cssSRI": "sha256-cS9Vc2OBt9eUf4sykRWukeFYaInL29+myBmFDSa7F/U=",52 "faviconSRI": "sha256-GhTyE+McTU79R4+pRO6ih+4TfsTOrpPwD8ReKFzb3PM=",53 "jsSRI": "sha256-4QG1Uza2GgGdlBL3RCBCGtGeZB6bDbsw8OltCMGeJsA=",54 })55 if err != nil {56 panic(err)57 }58 }59}...
CrossOrigin
Using AI Code Generation
1import (2func main() {3 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {4 fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))5 })6 http.ListenAndServe(":8080", nil)7}8import (9func main() {10 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {11 fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))12 })13 http.ListenAndServe(":8080", nil)14}15 var xhttp = new XMLHttpRequest();16 xhttp.onreadystatechange = function() {17 if (this.readyState == 4 && this.status == 200) {18 document.getElementById("demo").innerHTML = this.responseText;19 }20 };21 xhttp.send();
CrossOrigin
Using AI Code Generation
1import (2func main() {3 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {4 w.Header().Set("Access-Control-Allow-Origin", "*")5 fmt.Fprint(w, "Hello, world!")6 })7 http.ListenAndServe(":8080", nil)8}9import (10func main() {11 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {12 w.Header().Set("Access-Control-Allow-Origin", "*")13 fmt.Fprint(w, "Hello, world!")14 })15 http.ListenAndServe(":8080", nil)16}17import (18func main() {19 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {20 w.Header().Set("Access-Control-Allow-Origin", "*")21 fmt.Fprint(w, "Hello, world!")22 })23 http.ListenAndServe(":8080", nil)24}25import (26func main() {27 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {28 w.Header().Set("Access-Control-Allow-Origin", "*")29 fmt.Fprint(w, "Hello, world!")30 })31 http.ListenAndServe(":8080", nil)32}33import (34func main() {35 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {36 w.Header().Set("Access-Control-Allow-Origin", "*")37 fmt.Fprint(w, "Hello, world!")38 })39 http.ListenAndServe(":8080", nil)40}41import (42func main() {43 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {44 w.Header().Set("Access-Control-Allow-Origin", "*")45 fmt.Fprint(w, "Hello, world!")46 })47 http.ListenAndServe(":808
CrossOrigin
Using AI Code Generation
1import (2func main() {3 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {4 w.Header().Set("Access-Control-Allow-Origin", "*")5 http.ServeFile(w, r, "1.html")6 })7 http.ListenAndServe(":8080", nil)8}9 var btn = document.getElementById("btn");10 btn.onclick = function () {11 var xhttp = new XMLHttpRequest();12 xhttp.onload = function () {13 alert(xhttp.responseText);14 };15 xhttp.send();16 }17import (18func main() {19 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {20 w.Write([]byte("Hello World!"))21 })22 http.ListenAndServe(":8080", nil)23}24import (25func main() {26 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {27 w.Header().Set("Access-Control-Allow-Origin", "*")28 w.Write([]byte("Hello World!"))29 })30 http.ListenAndServe(":8080", nil)31}
CrossOrigin
Using AI Code Generation
1import "net/http"2func main() {3 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {4 w.Header().Set("Access-Control-Allow-Origin", "*")5 w.Write([]byte("Hello World"))6 })7 http.ListenAndServe(":8080", nil)8}9import (10func main() {11 req, err := http.NewRequest("GET", url, nil)12 if err != nil {13 log.Fatal(err)14 }15 client := &http.Client{}16 resp, err := client.Do(req)17 if err != nil {18 log.Fatal(err)19 }20 defer resp.Body.Close()21 fmt.Println(resp.Header)22}23import (24func main() {25 req, err := http.NewRequest("GET", url, nil)26 if err != nil {27 log.Fatal(err)28 }29 client := &http.Client{}30 resp, err := client.Do(req)31 if err != nil {32 log.Fatal(err)33 }34 defer resp.Body.Close()35 fmt.Println(resp.Header)36}37import (38func main() {39 req, err := http.NewRequest("GET", url, nil)
CrossOrigin
Using AI Code Generation
1import (2func main() {3 fmt.Println(js.Global.Call("CrossOrigin", port, path, handler))4}5import (6func main() {7 fmt.Println(js.Global.Call("CrossOrigin", port, path, handler))8}9import (10func main() {11 fmt.Println(js.Global.Call("CrossOrigin", port, path, handler))12}13import (14func main() {15 fmt.Println(js.Global.Call("CrossOrigin", port, path, handler))16}
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!!