Skip to content

Commit

Permalink
better godoc
Browse files Browse the repository at this point in the history
  • Loading branch information
jweslley committed Jun 4, 2017
1 parent 1de55d4 commit 405f8ef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -50,7 +50,7 @@ Output:
To finish the tunnel just interrupt the program (`Ctrl-C`).


## API [GoDoc][]
## API - [GoDoc][]

The localtunnel client is also usable through an API (for test integration, automation, etc).

Expand Down Expand Up @@ -94,7 +94,7 @@ if (err != nil) {
tunnel.Close()
```

For more information, check the [documentation][GoDoc].
For more information, check out the [documentation][GoDoc].


## Bugs and Feedback
Expand Down
34 changes: 32 additions & 2 deletions localtunnel.go
@@ -1,4 +1,25 @@
// Package localtunnel implements a client library for https://localtunnel.me
//
// localtunnel allows you to expose your localhost to the world for easy testing and sharing!
//
// Exposing a local port:
//
// import "github.com/jweslley/localtunnel"
//
// ...
//
// var port := 8000
// var tunnel := localtunnel.NewLocalTunnel(port)
// var err := tunnel.Open()
// if (err != nil) {
// fmt.Printf("your url is: %s\n", tunnel.URL())
// }
//
// ...
//
// tunnel.Close()
//
//
package localtunnel

import (
Expand Down Expand Up @@ -43,6 +64,7 @@ func NewTunnel(host string, port int) *Tunnel {
return DefaultClient.NewTunnel(host, port)
}

// Tunnel forwards remote requests to another server, typically to a port on localhost.
type Tunnel struct {
c *Client
m sync.Mutex
Expand All @@ -62,13 +84,19 @@ func (t *Tunnel) RemotePort() int { return t.remotePort }
func (t *Tunnel) LocalHost() string { return t.localHost }
func (t *Tunnel) LocalPort() int { return t.localPort }
func (t *Tunnel) Subdomain() string { return t.subdomain }
func (t *Tunnel) URL() string { return t.url }
func (t *Tunnel) MaxConn() int { return t.maxConn }

// URL at which the localtunnel is exposed.
func (t *Tunnel) URL() string { return t.url }

// MaxConn is the maximum number of connections allowed.
func (t *Tunnel) MaxConn() int { return t.maxConn }

// Open setup the tunnel creating connections between the remote and local servers.
func (t *Tunnel) Open() error {
return t.OpenAs("?new")
}

// Open setup the tunnel creating connections between the remote and local servers with a custom subdomain.
func (t *Tunnel) OpenAs(subdomain string) error {
t.m.Lock()
defer t.m.Unlock()
Expand All @@ -83,6 +111,7 @@ func (t *Tunnel) OpenAs(subdomain string) error {
return nil
}

// Close closes all tunnel's connections.
func (t *Tunnel) Close() {
t.m.Lock()
defer t.m.Unlock()
Expand All @@ -95,6 +124,7 @@ func (t *Tunnel) Close() {
close(t.closeCh)
}

// Closing is a channel which is closed when the tunnel is closed.
func (t *Tunnel) Closing() <-chan struct{} {
return t.closeCh
}
Expand Down

0 comments on commit 405f8ef

Please sign in to comment.