Skip to main content
ngrok-gin serves a Gin router through an ngrok endpoint with one call:
The library is built on the Go SDK. Serve opens an endpoint listener and hands it to Gin’s RunListener, so Gin serves ngrok traffic the same way it serves a local port.
ngrok-gin is published on the Go module proxy at v0.1.0 and maintained in the ngrok-samples/ngrok-gin repository.

What you’ll need

1. Install the library

In your Go module, run:

2. Set your auth token

Export your auth token as an environment variable:
The library uses the Go SDK’s default agent, which reads NGROK_AUTHTOKEN from the environment.

3. Serve your router

Replace router.Run() with ngrokgin.Serve():
main.go
Serve blocks until the listener closes or a connection error occurs, the same as router.Run().

4. Test your endpoint

Run your app:
The library prints Ingress established at: followed by the public URL. With an empty Config, that URL is your account’s dev domain. Open it in your browser to see your Gin app.

Configuration

Pass a Config to set the URL, add a Traffic Policy, or change the binding:

Multiple endpoints

ServeMany opens one endpoint per Endpoint, each with its own router and Config, on a single agent:
Serve is the one-endpoint case of ServeMany. To put one router behind several listeners, reuse the same *gin.Engine in more than one Endpoint. Every endpoint needs its own URL, or Pooling: true on each endpoint that shares one. If two endpoints would share a URL without pooling, including two endpoints that both leave URL empty and land on your dev domain, ServeMany returns a *ngrokgin.CollisionError before opening a session. Without that check, ngrok lets the most recently opened listener win and the other goes unreachable with no error.

Limits and availability

  • The library opens HTTP endpoints only. For TCP or TLS endpoints, use the Go SDK directly.
  • An internal binding requires a URL that ends in .internal. ngrok rejects any other URL with ERR_NGROK_9029.
  • A URL that another agent or a Cloud Endpoint already claims fails with ERR_NGROK_334.
  • Endpoint counts and domains follow your plan’s limits. See free plan limits.

What’s next?