Open-Source Package ngrok-go Aims to Make it Easier to Embed Ingress into Go Apps

MMS Founder
MMS Sergio De Simone

Article originally posted on InfoQ. Visit InfoQ

Ngrok-go is an idiomatic Go package that enables Go applications to securely receive network requests through ngrok’s ingress-as-a-service platform as if they were listening on a local port.

ngrok-go aims to simplify the creation of network ingress by taking care of a number of low-level network primitives at different layers of the network stack that developers are responsible to set up today to enable network ingress. That includes DNS, TLS Certificates, network-level CIDR policies, IP and subnet routing, load balancing, VPNs and NATs.

ngrok-go can be seen as a way to package the ngrok agent and embed it into a Go app, thus removing a significant complexity for apps that used to bundle ngrok to create network ingress, such as IoT devices, CI/CD pipelines, and others.

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!

To embed ingress through ngrok into a Go app, all developers need to do is calling the ngrok.Listen primitive provided by ngrok-go. If your environment has an ngrok authtoken, the call to Listen will initiate a secure and persistent connection to ngrok and transmit any configuration requirement you specified, including URL, authentication, IP restrictions, and so on, for example:

ngrok.Listen(ctx, 
       config.HTTPEndpoint(
        config.WithDomain("my-app.ngrok.io"),
        config.WithAllowCDIRString("192.30.252.0/22"),
        config.WithCircuigBreaker(0.8),
        config.WithCompression(),
        config.WithOAuth("github")
       ), 
       ngrok.WithAuthtokenFromEnv(),
)

All the policies specified when calling Listen are enforced by ngrok, which rejects all unauthorized requests at the edge, which means that only valid requests will ever reach the Go app.

Another advantage of using ngrok-go is its “portability” with respect to ingress. This means an app using it will just run the same way independent of the underlying platform, be it bare metal, a virtual machine, AWS, Azure, Kubernetes, and so on.

While ngrok chose Go as the first language to support, support for other languages is already in the works, including Rust and JavaScript. Other languages like Java, C#, Python and Ruby are expected to be included in the roadmap soon, also based on users’ feedback.

If you are interested to try it out, ngrok-go is available on GitHub and a good place to start is it official getting started guide.

About the Author

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.