Skip to main content

Download & Install

The fastest way to put anything on the internet.

GoSDK

1

Get started with Go

Clone the ngrok Go SDK example:

git clone git@github.com:ngrok/go-sdk-example.git && cd go-sdk-example

Install the ngrok Go SDK:

go get golang.ngrok.com/ngrok/v2

Add ngrok to your app:

main.go

package main import (	"context"	"log"	"golang.ngrok.com/ngrok/v2") func connectNgrok() {	fwd, err := ngrok.Forward(context.Background(),		ngrok.WithUpstream("http://localhost:8085"),	)	if err != nil {		log.Fatal(err)	}	log.Println("Available at:", fwd.URL())	select {}}
2

Run your app

NGROK_AUTHTOKEN="<YOUR_AUTHTOKEN>" go run main.go

Don’t have an authtoken? for a free account.

Open your ngrok URL in a browser to see it working!

You’re all set. What’s next?

tp := `on_http_request:	# redirect users to Google to log in	- actions:		- type: oauth			config:				provider: google 	# allow logins *only* from acme.com	- expressions:		- "!actions.ngrok.oauth.identity.email.endsWith('@acme.com')"		actions:		- type: deny` fwd, err := ngrok.Forward(ctx, ngrok.WithUpstream("http://localhost:8085"), ngrok.WithTrafficPolicy(tp))
tp := `on_http_request:	# verify webhook signatures from your provider	- actions:		- type: verify-webhook			config:				provider: github				# access your signing key from a secure ngrok vault				# no cleartext secrets in your policy, friend				secret: ${secrets.get('webhook-vault', 'github-secret')}` fwd, err := ngrok.Forward(ctx, ngrok.WithUpstream("http://localhost:8085"), ngrok.WithTrafficPolicy(tp))
tp := `on_http_request:	# redirect users to your OpenID provider to log in	- actions:		- type: openid-connect			config:				issuer_url: https://accounts.google.com				# access your OIDC details from a secure ngrok vault				client_id: ${secrets.get('auth-vault', 'oidc-client-id')}				client_secret: ${secrets.get('auth-vault', 'oidc-client-secret')}				scopes:					- openid					- email` fwd, err := ngrok.Forward(ctx, ngrok.WithUpstream("http://localhost:8085"), ngrok.WithTrafficPolicy(tp))
tp := `on_http_request:	- actions:		- type: basic-auth			config:				credentials:					# add up to 10 username:password pairs, all stored safely in a vault					- user01:${secrets.get('basic-auth-vault', 'password01')}					- user02:${secrets.get('basic-auth-vault', 'password02')}` fwd, err := ngrok.Forward(ctx, ngrok.WithUpstream("http://localhost:8085"), ngrok.WithTrafficPolicy(tp))

Inspect every detail of your traffic

Watch the flow in real time, then dig into the headers, body, latency, response, and more for every request.

Peruse the Go SDK quickstart

Follow along to embed ngrok into your app and use Traffic Policy for auth and traffic transformation.

Bring your own domain

Paid feature

Create a DNS CNAME record to use your own domain name for your endpoint URL.

func connectNgrok() {	fwd, err := ngrok.Forward(context.Background(),		ngrok.WithUpstream("http://localhost:8085"),		ngrok.WithURL("app.acme.com"),	)}

Listen, don't forward

Serve traffic directly on an ngrok listener without forwarding. Your handler receives connections straight from the internet.

func main() {		ln, _ := ngrok.Listen(ctx)		http.Serve(ln, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {				fmt.Fprintln(w, "Hello from ngrok-go!")		}))}