localtunnel

package module
v0.0.0-...-8a80448 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2017 License: MPL-2.0 Imports: 11 Imported by: 2

README

LocalTunnel Client Library for Go Build Status

A localtunnel.me client library exposing localtunnel connections through a net.Listener implementation. While localtunnel only supports forwarding HTTP(S) connections, this is useful as you can hook it up to http.Server directly. Neat, if writing test-suites or command-line utilities exposing web-hooks of localtunnel.

// Setup a listener for localtunnel
listener, err := localtunnel.Listen(localtunnel.Options{})

// Create your server...
server := http.Server{
    Handler: http.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
        w.WriteHeader(200)
        ...
    })
}

// Handle request from localtunnel
server.Serve(listener)

See documentation for more details.

License

This package is released under MPLv2.

Documentation

Overview

Package localtunnel implements a client library for https://localtunnel.me

In addition to providing the LocalTunnel client which will forward requests from subdomain.localtunnel.me to a port on localhost. This package also provides an implementation of net.Listener which exposes connections from localtunnel. This enables users to serve http requests directly, without listening to a port on localhost.

// Setup a listener for localtunnel
listener, err := localtunnel.Listen(localtunnel.Options{})

// Create your server...
server := http.Server{
    Handler: http.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
        w.WriteHeader(200)
        ...
    })
}

// Handle request from localtunnel
server.Serve(listener)

Index

Constants

This section is empty.

Variables

View Source
var DefaultBaseURL = "https://localtunnel.me"

DefaultBaseURL is the default value for the Options.BaseURL

View Source
var DefaultMaxConnections = 10

DefaultMaxConnections is the default value for Options.MaxConnections

View Source
var ErrListenerClosed = errors.New("listener was closed")

ErrListenerClosed indicates that the listener as closed

Functions

This section is empty.

Types

type Addr

type Addr struct {
	URL string
}

Addr implements net.Addr

func (Addr) Network

func (a Addr) Network() string

Network return "localtunnel"

func (Addr) String

func (a Addr) String() string

String returns the URL

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

Listener implements a net.Listener using localtunnel.me

func Listen

func Listen(options Options) (*Listener, error)

Listen creates a *Listener that gets incoming connections from localtunnel.me

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

Accept returns the next incoming connection

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

Addr returns an address representation in compliance with net.Listener

func (*Listener) Close

func (l *Listener) Close() error

Close the listener, breaking all connections proxied by this listener

func (*Listener) URL

func (l *Listener) URL() string

URL returns the URL that the listener is exposed on.

type LocalTunnel

type LocalTunnel struct {
	// contains filtered or unexported fields
}

LocalTunnel forwards remote requests to a port on localhost

func New

func New(port int, host string, options Options) (*LocalTunnel, error)

New returns a LocalTunnel forwarding requests to port on host

host defaults to 'localhost', and options defaults to using localtunnel.me

func (*LocalTunnel) Close

func (lt *LocalTunnel) Close() error

Close the localtunnel aborting all connections

func (*LocalTunnel) URL

func (lt *LocalTunnel) URL() string

URL returns the URL at which the localtunnel is exposed

type Logger

type Logger interface {
	Println(v ...interface{})
}

Logger is implemented by built-in log.Logger as well as logrus.Entry

var DefaultLogger Logger = logger{}

DefaultLogger is the default value for Options.Log, it does nothing.

type Options

type Options struct {
	Subdomain      string
	BaseURL        string
	MaxConnections int
	Log            Logger
}

Options for connecting to a localtunnel server

Jump to

Keyboard shortcuts

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