{"id":13764050,"url":"https://github.com/jaschaephraim/lrserver","last_synced_at":"2025-04-06T22:10:21.405Z","repository":{"id":18641150,"uuid":"21847668","full_name":"jaschaephraim/lrserver","owner":"jaschaephraim","description":"LiveReload server for Go [golang]","archived":false,"fork":false,"pushed_at":"2024-03-06T23:32:15.000Z","size":106,"stargazers_count":128,"open_issues_count":0,"forks_count":13,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-30T21:06:57.410Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaschaephraim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2014-07-15T05:36:53.000Z","updated_at":"2024-12-16T15:10:39.000Z","dependencies_parsed_at":"2023-02-13T20:00:57.313Z","dependency_job_id":"b7e6b807-2e69-4b3c-9893-6a08934e8535","html_url":"https://github.com/jaschaephraim/lrserver","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaschaephraim%2Flrserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaschaephraim%2Flrserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaschaephraim%2Flrserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaschaephraim%2Flrserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaschaephraim","download_url":"https://codeload.github.com/jaschaephraim/lrserver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247557767,"owners_count":20958047,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-08-03T15:01:10.920Z","updated_at":"2025-04-06T22:10:21.384Z","avatar_url":"https://github.com/jaschaephraim.png","language":"JavaScript","funding_links":[],"categories":["工具库`可以提升效率的通用代码库和工具`","Utilities","實用工具","公用事业公司","实用工具","工具库","Utility"],"sub_categories":["查询语","Advanced Console UIs","Utility/Miscellaneous","高級控制台界面","HTTP Clients","实用程序/Miscellaneous","高级控制台界面","交流","Fail injection","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"readme":"# `lrserver` LiveReload server for Go #\n\nGolang package that implements a simple LiveReload server as described in the [LiveReload protocol](http://feedback.livereload.com/knowledgebase/articles/86174-livereload-protocol).\n\nUsing the recommended default port 35729:\n\n- `http://localhost:35729/livereload.js` serves the LiveReload client JavaScript (https://github.com/livereload/livereload-js)\n\n- `ws://localhost:35729/livereload` communicates with the client via web socket.\n\nFile watching must be implemented by your own application, and reload/alert\nrequests sent programmatically.\n\nMultiple servers can be instantiated, and each can support multiple connections.\n\n## Full Documentation: [![GoDoc](https://godoc.org/github.com/jaschaephraim/lrserver?status.svg)](http://godoc.org/github.com/jaschaephraim/lrserver) ##\n\n## Basic Usage ##\n\n### Get Package ###\n\n```bash\ngo get github.com/jaschaephraim/lrserver\n```\n\n### Import Package ###\n\n```go\nimport \"github.com/jaschaephraim/lrserver\"\n```\n\n### Instantiate Server ###\n\n```go\nlr := lrserver.New(lrserver.DefaultName, lrserver.DefaultPort)\n```\n\n### Start Server ###\n\n```go\ngo func() {\n    err := lr.ListenAndServe()\n    if err != nil {\n        // Handle error\n    }\n}()\n```\n\n### Send Messages to the Browser ###\n\n```go\nlr.Reload(\"file\")\nlr.Alert(\"message\")\n```\n\n## Example ##\n\n```go\nimport (\n    \"log\"\n    \"net/http\"\n\n\t\"github.com/fsnotify/fsnotify\"\n\t\"github.com/jaschaephraim/lrserver\"\n)\n\n// html includes the client JavaScript\nconst html = `\u003c!doctype html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n  \u003ctitle\u003eExample\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003cscript src=\"http://localhost:35729/livereload.js\"\u003e\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e`\n\nfunc Example() {\n    // Create file watcher\n    watcher, err := fsnotify.NewWatcher()\n    if err != nil {\n        log.Fatalln(err)\n    }\n    defer watcher.Close()\n\n    // Add dir to watcher\n    err = watcher.Add(\"/path/to/watched/dir\")\n    if err != nil {\n        log.Fatalln(err)\n    }\n\n    // Create and start LiveReload server\n    lr := lrserver.New(lrserver.DefaultName, lrserver.DefaultPort)\n    go lr.ListenAndServe()\n\n    // Start goroutine that requests reload upon watcher event\n    go func() {\n        for {\n            select {\n            case event := \u003c-watcher.Events:\n                lr.Reload(event.Name)\n            case err := \u003c-watcher.Errors:\n                log.Println(err)\n            }\n        }\n    }()\n\n    // Start serving html\n    http.HandleFunc(\"/\", func(rw http.ResponseWriter, req *http.Request) {\n        rw.Write([]byte(html))\n    })\n    http.ListenAndServe(\":3000\", nil)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaschaephraim%2Flrserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaschaephraim%2Flrserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaschaephraim%2Flrserver/lists"}