portal

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

README

Portal

Go Reference Release

A Go implementation of HTTP tunneling through a tunnel

Overview

The main goal of this project is to provide access from cloud to on-prem without opening ports on-prem. This library provides a mechanism to build a 2-node HTTP tunnel.

The tunnel has two sides: client and server. An on-prem application running tunnel client will connect to tunnel server running in cloud. Proxy port can be opened on cloud side to allow access to on-prem via HTTP tunnelling: https://en.wikipedia.org/wiki/HTTP_tunnel

               +---------+
               | Cloud   |
               | HTTPS   |
               | Client  |
               +----+----+
                    |
                    | proxy
            +-------v-------+
            |               |
            | Tunnel Server |
            |     using     |
            |Portal library |
            |               |
            +-----+---^-----+
 Internet         |   |
------------------+---+--------------------
 On-prem          |   |
            +-----v---+-----+
            |               |
            | Tunnel Client |
            |     using     |
            |Portal library |
            |               |
            +-------+-------+
                    |
                    |
               +----v----+
               | On-prem |
               | HTTPS   |
               | Server  |
               +---------+

Install

go get github.com/oatcode/portal

Usage

Wrap the tunnel connection with Framer interface and use Serve:

tn := portal.Tunnel{}
tn.Serve(ctx, framer)

Framer interface is for reading and writing messages with boundaries (i.e. frame). The examples show a simple length/bytes and WebSocket framer.

For incoming proxy connections, pass the processing to the tunnel with:

tn.Hijack(w, r)

Documentation

Overview

Package portal provides the ability to build a 2-node HTTP tunnel

Index

Constants

This section is empty.

Variables

View Source
var (
	// Logf is for setting logging function
	Logf func(string, ...interface{})
)

Functions

This section is empty.

Types

type Framer added in v0.1.5

type Framer interface {
	// Read reads a message from the connection
	// The returned byte array is of the exact length of the message
	Read() (b []byte, err error)

	// Write writes the entire byte array as a message to the connection
	Write(b []byte) error

	// Close closes the connection
	Close(err error) error
}

Framer is for reading and writing messages with boundaries (i.e. frame)

type Tunnel added in v1.1.0

type Tunnel struct {
	// Create a connection on receiving proxy HTTP CONNECT from remote
	ProxyConnect func(context.Context, string) (net.Conn, error)
	// contains filtered or unexported fields
}

Tunnel is for building a tunnel connection between two nodes

func (*Tunnel) Hijack added in v1.1.0

func (tn *Tunnel) Hijack(w http.ResponseWriter, r *http.Request) error

Hijack hijacks the proxied HTTP connection. The function name is borrowed from http.Hijacker. If this function returns no error, the caller should not use the http.ResponseWriter anymore. The only error returned is when hijacking is not supported.

func (*Tunnel) Serve added in v1.1.0

func (tn *Tunnel) Serve(ctx context.Context, c Framer)

Serve starts the tunnel communication with the remote side. This blocks until connection is closed or context is cancelled.

Directories

Path Synopsis
examples
simple-tunnel command
ws-tunnel command
pkg

Jump to

Keyboard shortcuts

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