{"id":20655530,"url":"https://github.com/postmannen/htmltemplateoversocket","last_synced_at":"2026-04-14T00:32:12.427Z","repository":{"id":91227654,"uuid":"145722997","full_name":"postmannen/htmltemplateoversocket","owner":"postmannen","description":"Ask for a Go HTML template from JavaScript Client in Web browser to Go backend server over a websocket, and render it in the browser.","archived":false,"fork":false,"pushed_at":"2018-09-09T20:33:29.000Z","size":177,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T22:39:44.060Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/postmannen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-22T14:46:46.000Z","updated_at":"2019-03-25T17:25:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"4d027f20-6d87-4c4b-a89e-6b4b8a89782d","html_url":"https://github.com/postmannen/htmltemplateoversocket","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/postmannen/htmltemplateoversocket","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postmannen%2Fhtmltemplateoversocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postmannen%2Fhtmltemplateoversocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postmannen%2Fhtmltemplateoversocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postmannen%2Fhtmltemplateoversocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/postmannen","download_url":"https://codeload.github.com/postmannen/htmltemplateoversocket/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postmannen%2Fhtmltemplateoversocket/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31776926,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T00:11:49.126Z","status":"ssl_error","status_checked_at":"2026-04-14T00:10:29.837Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T18:11:37.573Z","updated_at":"2026-04-14T00:32:12.399Z","avatar_url":"https://github.com/postmannen.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# websocket test using JSON\n\n## Execute a Go/Golang HTML template existing on Go backend server from JavaScript in Web browser\n\nThe idea is:\n\n* The user do some action in the browser. For example ask the server for a Go Web Template to be drawn.\n* The user action is a JSON object in the form {\"Command\":\"xxxx\",\"Argument\":\"yyyy\"} where Command can be \"executeTemplate\", and Action can be \"someTemplate\".\n* Send the JSON object over the Socket to the Server.\n* The Server then Decodes the JSON object.\n* Then the server checks the Command, and if it is for example \"executeTemplate\" then it will check it's map containing all the Argument to Template mappings, and pick the correct template.\n* The template is then Executed on the server, but instead of writing the template to http.ResponseWriter we write the template to a bytes.Buffer. The buffer is then stripped of leading and ending spaces, and converted to a string, and put into the JSON object.\n* The Json object containing the template (pure html code) is then put onto the socket and sendt to the client.\n* The client reads the socket and renders the html on the page in the browser.\n* The JSON of commands is read from file, and then converted to a map.\n* If there is a change in the JSON file the map is automatically updated when file is changed. This is done with the mapfile package.\n\n![alt text](https://github.com/postmannen/websocket-testing-json/blob/master/doc/websocket-diagram.png)\n\n## Structure of JSON\n\n* {\"Command\":\"executeTemplate\",\"Argument\":\"addHeader\"}\n* {\"Command\":\"executeTemplate\",\"Argument\":\"addButton\"}\n\n## Structure of Argument to Template map\n\n    s.msgToTemplateMap = map[string]string{\n        \"addButton\":    \"buttonTemplate1\",\n        \"addHeader\":    \"socketTemplate1\",\n        \"addParagraph\": \"paragraphTemplate1\",\n    }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostmannen%2Fhtmltemplateoversocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpostmannen%2Fhtmltemplateoversocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostmannen%2Fhtmltemplateoversocket/lists"}