(out io.Writer, url, token, wsURL string, activateHook func() error)
| 83 | } |
| 84 | |
| 85 | func runFwd(out io.Writer, url, token, wsURL string, activateHook func() error) error { |
| 86 | if url == "" { |
| 87 | fmt.Fprintln(os.Stderr, "notice: no `--url` specified; printing webhook payloads to stdout") |
| 88 | } |
| 89 | for i := 0; i < 3; i++ { |
| 90 | err := handleWebsocket(out, url, token, wsURL, activateHook) |
| 91 | if err != nil { |
| 92 | // If the error is a server disconnect (1006), retry connecting |
| 93 | if websocket.IsCloseError(err, websocket.CloseAbnormalClosure) { |
| 94 | time.Sleep(5 * time.Second) |
| 95 | continue |
| 96 | } else if websocket.IsCloseError(err, websocket.CloseNormalClosure) { |
| 97 | return nil |
| 98 | } |
| 99 | return err |
| 100 | } |
| 101 | } |
| 102 | return fmt.Errorf("unable to connect to webhooks server, forwarding stopped") |
| 103 | } |
| 104 | |
| 105 | // handleWebsocket mediates between websocket server and local web server |
| 106 | func handleWebsocket(out io.Writer, url, token, wsURL string, activateHook func() error) error { |
no test coverage detected