Documentation ¶
Overview ¶
Package gonnel provides direct API tunnel using code. The implementation in this project inspired from ngrok wrapper node.js that using EventEmitter. In this package channel used to check if binary running successfully or not
The Client package intended to handle all function that provided from binary like using auth token or create a tunnel
Here is a simple example, initialize client binary and auth token automatically by running StartServer
client, err := gonnel.NewClient(gonnel.Options{ BinaryPath: "../ngrok-bin/ngrok_linux", }) if err != nil { fmt.Println(err) } defer client.Close() done := make(chan bool) go client.StartServer(done) <-done
This package also can directly create tunnel if you already started ngrok binary separately, WebUIAddress type need hostname and port
client := go_ngrok.Client{ WebUIAddress: "127.0.0.1:4040", LogApi: true, } // Create pointer tunnel t := &go_ngrok.Tunnel{ Name: "awesome", Auth: "username:password", Inspect: false, LocalAddress: "4040", Proto: go_ngrok.HTTP, } if err := client.CreateTunnel(t); err != nil { log.Fatalln(err) }
Index ¶
- type Client
- func (c *Client) AddTunnel(t *Tunnel)
- func (c *Client) Close() error
- func (c *Client) CloseTunnel(t *Tunnel) (err error)
- func (c *Client) ConnectAll() error
- func (c *Client) CreateTunnel(t *Tunnel) (err error)
- func (c *Client) DisconnectAll() error
- func (c *Client) Signal(signal os.Signal) error
- func (c *Client) StartServer(isReady chan bool)
- type Options
- type Protocol
- type Tunnel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { Options *Options // Options that will be used for command Tunnel []*Tunnel // List of all tunnel WebUIAddress string // Client server for API communication LogApi bool // Log response from API or not // contains filtered or unexported fields }
Client that provides all option and tunnel
You don't need NewClient method if server client already started
func NewClient ¶
NewClient that return Client pointer
Client pointer can be used to close binary or start binary
func (*Client) CloseTunnel ¶
CloseTunnel that close tunnel from ngrok server
Close tunnel call API using DELETE method
func (*Client) ConnectAll ¶
ConnectAll connect all tunnels that created
func (*Client) CreateTunnel ¶
CreateTunnel that create connection to ngrok server
Error will be from api ngrok server client, retries is used because server client not always success when started. Need at least 1 or 2 second to start.
func (*Client) DisconnectAll ¶
DisconnectAll disconnect all tunnels that previously tunneled
func (*Client) StartServer ¶
StartServer will be run command from previous options
Channel needed to send information about WebUI started or not. stdout will be pipe and check using regex.
type Options ¶
type Options struct { SubDomain string // Sub domain config if you're using premium plan AuthToken string // Auth token to authenticate client Region string // Region that will tunneling from ConfigPath string // Path config to store auth token or specific WebUI port BinaryPath string // Binary file that will be running LogBinary bool // You can watch binary log or not IgnoreSignals bool // Run child processes in a separate process group to ignore signals }
Options that represents command that will be used to start binary
Not all of this option necessary, if AuthToken provided then binary will run auth token first.
func (*Options) AuthTokenCommand ¶
AuthTokenCommand that will be authenticate api token
type Tunnel ¶
type Tunnel struct { Proto Protocol // Protocol that use in tunneling process Name string // A name that used for creating or closing LocalAddress string // Can be host with port or port only Auth string // Username & password that will authenticate to access tunnel Inspect bool // Inspect transaction data tunnel that will be logged in binary file RemoteAddress string // Result ngrok connection address IsCreated bool // Information tunnel created or not }
Tunnel will be used in creating or closing a tunnel. a tunnel also can connect to ngrok directly as long ngrok client server already running