websocketproxy

module
v0.1.0-dyv.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2023 License: MIT

README

WebsocketProxy GoDoc Build Status

WebsocketProxy is an http.Handler interface build on top of dvonthenen/websocket that you can plug into your existing Go webserver to provide WebSocket reverse proxy.

Install

go get github.com/dvonthenen/websocketproxy

Example

Below is a simple server that proxies to the given backend URL

package main

import (
	"flag"
	"net/http"
	"net/url"

	"github.com/dvonthenen/websocketproxy"
)

var (
	flagBackend = flag.String("backend", "", "Backend URL for proxying")
)

func main() {
	u, err := url.Parse(*flagBackend)
	if err != nil {
		log.Fatalln(err)
	}

	err = http.ListenAndServe(":80", websocketproxy.NewProxy(u))
	if err != nil {
		log.Fatalln(err)
	}
}

Save it as proxy.go and run as:

go run proxy.go -backend ws://example.com:3000

Now all incoming WebSocket requests coming to this server will be proxied to ws://example.com:3000

Directories

Path Synopsis
pkg
interfaces
Package websocketproxy is a reverse proxy for WebSocket connections.
Package websocketproxy is a reverse proxy for WebSocket connections.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL