• Stars
    star
    597
  • Rank 72,004 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 1 year ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Embed ngrok secure ingress into your Go apps as a net.Listener with a single line of code.

Go Reference Go

ngrok-go

ngrok is a simplified API-first ingress-as-a-service that adds connectivity, security, and observability to your apps.

ngrok-go is an open source and idiomatic library for embedding ngrok networking directly into Go applications. If you’ve used ngrok before, you can think of ngrok-go as the ngrok agent packaged as a Go library.

ngrok-go lets developers serve Go apps on the internet in a single line of code without setting up low-level network primitives like IPs, certificates, load balancers and even ports! Applications using ngrok-go listen on ngrok’s global ingress network but they receive the same interface any Go app would expect (net.Listener) as if it listened on a local port by calling net.Listen(). This makes it effortless to integrate ngrok-go into any application that uses Go's net or net/http packages.

See examples/http/main.go for example usage, or the tests in online_test.go.

For working with the ngrok API, check out the ngrok Go API Client Library.

Installation

The best way to install the ngrok agent SDK is through go get.

go get golang.ngrok.com/ngrok

Documentation

A full API reference is included in the ngrok go sdk documentation on pkg.go.dev. Check out the ngrok Documentation for more information about what you can do with ngrok.

Quickstart

For more examples of using ngrok-go, check out the /examples folder.

The following example uses ngrok to start an http endpoint with a random url that will route traffic to the handler. The ngrok URL provided when running this example is accessible by anyone with an internet connection.

The ngrok authtoken is pulled from the NGROK_AUTHTOKEN environment variable. You can find your authtoken by logging into the ngrok dashboard.

You can run this example with the following command:

NGROK_AUTHTOKEN=xxxx_xxxx go run examples/http/main.go
package main

import (
	"context"
	"fmt"
	"log"
	"net/http"

	"golang.ngrok.com/ngrok"
	"golang.ngrok.com/ngrok/config"
)

func main() {
	if err := run(context.Background()); err != nil {
		log.Fatal(err)
	}
}

func run(ctx context.Context) error {
	tun, err := ngrok.Listen(ctx,
		config.HTTPEndpoint(),
		ngrok.WithAuthtokenFromEnv(),
	)
	if err != nil {
		return err
	}

	log.Println("tunnel created:", tun.URL())

	return http.Serve(tun, http.HandlerFunc(handler))
}

func handler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintln(w, "Hello from ngrok-go!")
}

Support

The best place to get support using ngrok-go is through the ngrok Slack Community. If you find bugs or would like to contribute code, please follow the instructions in the contributing guide.

License

ngrok-go is licensed under the terms of the MIT license.

See LICENSE for details.

More Repositories

1

sqlmw

Interceptors for database/sql
Go
457
star
2

ngrok-rust

Embed ngrok secure ingress into your Rust apps with a single line of code.
Rust
271
star
3

kubernetes-ingress-controller

The official ngrok Ingress Controller for Kubernetes
Go
167
star
4

webhooks.fyi

webhooks.fyi site
JavaScript
142
star
5

firewall_toolkit

golang library and tools for managing nftables
Go
80
star
6

ngrok-python

Embed ngrok secure ingress into your Python apps with a single line of code.
Rust
80
star
7

ngrok-javascript

Embed ngrok secure ingress into your Node.js apps with a single line of code.
Rust
75
star
8

docker-ngrok

docker images for the ngrok agent
Nix
47
star
9

ngrok-api-go

ngrok API client library for Golang
Go
41
star
10

ngrok-docs

ngrok's official documentation
JavaScript
35
star
11

ngrok-api-java

ngrok API client library for Java
Java
21
star
12

tableroll

Go
19
star
13

ngrok-java

Embed ngrok secure ingress into your Java apps with a single line of code.
Java
17
star
14

terraform-provider-ngrok

Ngrok exposes local servers behind NATs and firewalls to the public internet over secure tunnels. This provider helps you manage those resources via Terraform.
Go
17
star
15

ngrok-webhook-nodejs-sample

Sample webhook listener using NodeJS and ExpressJS
JavaScript
16
star
16

ngrok-api-python

ngrok API client library for Python
Python
15
star
17

ngrok-api-ruby

ngrok API client library for Ruby
Ruby
13
star
18

ngrok-api-typescript

ngrok API client library for Typescript and Javascript
TypeScript
7
star
19

ngrok-api-dotnet

ngrok API client library for .NET
C#
7
star
20

ngrok-api-scala

ngrok API client library for Scala
Scala
5
star
21

ngrok-docker-extension

ngrok Docker Desktop Extension
TypeScript
5
star
22

ngrok-systemd

5
star
23

muxado-go

Stream multiplexing for Go
Go
4
star
24

ngrok-tutorial

This will help us learn ngrok
JavaScript
4
star
25

choco-ngrok

ngrok agent chocolatey package
PowerShell
3
star
26

ngrok-api-rs

ngrok API client library for Rust
Rust
3
star
27

ngrok-java-demo

Demonstrates how to use ngrok-java
Java
2
star
28

ngrok-ipaas-example

Example of a Remote API for integration with iPaaS solutions
JavaScript
1
star
29

mantle

@ngrok/mantle ui component library
TypeScript
1
star
30

homebrew-ngrok

ngrok agent homebrew tap
Ruby
1
star
31

ngrok-sdk-serverless-example

An example of using the ngrok-js NodeJS SDK in a serverless AWS App Runner application.
JavaScript
1
star
32

examples

Sample Project using ngrok
Go
1
star