(r io.Reader)
| 246 | ` |
| 247 | |
| 248 | func appendDevReloaderScript(r io.Reader) (*html.Node, error) { |
| 249 | doc, err := html.Parse(r) |
| 250 | if err != nil { |
| 251 | return nil, fmt.Errorf("parsing HTML: %w", err) |
| 252 | } |
| 253 | var f func(*html.Node) |
| 254 | f = func(n *html.Node) { |
| 255 | if n.Type == html.ElementNode && n.Data == "body" { |
| 256 | text := &html.Node{ |
| 257 | Type: html.TextNode, |
| 258 | Data: devReloaderScript, |
| 259 | } |
| 260 | script := &html.Node{ |
| 261 | Type: html.ElementNode, |
| 262 | Data: "script", |
| 263 | DataAtom: atom.Script, |
| 264 | Attr: []html.Attribute{ |
| 265 | {Key: "type", Val: "text/javascript"}, |
| 266 | }, |
| 267 | } |
| 268 | script.AppendChild(text) |
| 269 | n.AppendChild(script) |
| 270 | } |
| 271 | for c := n.FirstChild; c != nil; c = c.NextSibling { |
| 272 | f(c) |
| 273 | } |
| 274 | } |
| 275 | f(doc) |
| 276 | return doc, nil |
| 277 | } |
| 278 | |
| 279 | func debounceEvents(ctx context.Context, interval time.Duration, watcher *fsnotify.Watcher, fn func(event fsnotify.Event)) { |
| 280 | var mu sync.Mutex |
no test coverage detected