Skip to content

Commit 41fe969

Browse files
implement new v2 API
see CHANGELOG.md for details
1 parent 87bc168 commit 41fe969

114 files changed

Lines changed: 5529 additions & 2377 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## 2.0.0
2+
3+
- This is a breaking-change release that updates ngrok-go to a new, simplified API.
4+
5+
Enhancements:
6+
- Dramatically simplified the API to remove many overlapping options, options that are now deprecated, unnecessary convenience functions, etc.
7+
- Simplified the API by creating a unified API by removing all protocol-specific behaviors (which have all been moved to Traffic Policy).
8+
- Removed the config package. All of its options are now folded into the top-level package or removed because they were migrated into Traffic Policy.
9+
- Updates the API to use new ngrok terminology of Agents, Endpoints and Traffic Policy.
10+
- Removes unnecessary functionality that has been moved to Traffic Policy.
11+
- Removes functionality that is now deprecated (like labeled tunnels).
12+
- Added support for agent-based TLS termination and Mutual TLS termination.
13+
- Removed the prototype policy package that was not well supported.
14+
- Separated out a concept of an Agent from its Sesssion which were previously co-mingled.
15+
116
## 1.12.1
217

318
Fixes:
@@ -9,7 +24,6 @@ Fixes:
924
Breaking changes:
1025

1126
- Renames pre-release option `WithAllowsPooling` to `WithPoolingEnabled`
12-
-
1327

1428
## 1.11.0
1529

CONTRIBUTING.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,10 @@ For any larger changes or features, please [open a new issue](https://github.com
1616

1717
The library can be compiled with `go build`.
1818

19-
To run tests, `go test`.
19+
To run tests, use `go test ./...`.
2020

2121
Tests are split into a number of categories that can be enabled as desired via environment variables. By default, only offline tests run which validate tunnel protocol RPC messages generated from the `config` APIs. The other tests are gated behind the following environment variables:
2222

23-
* `NGROK_TEST_ONLINE`: All online tests require this variable to be set
24-
* `NGROK_TEST_AUTHED`: Enables tests that require an ngrok account and that the authtoken is set in `NGROK_AUTHTOKEN`.
25-
* `NGROK_TEST_PAID`: Enables online, authenticated tests that require access to paid features. If your subscription doesn't support a feature being tested, you should see error messages to that effect.
26-
* `NGROK_TEST_LONG`: Enables online tests that may take longer than most. May also require the `AUTHED` and/or `PAID` groups enabled.
27-
* `NGROK_TEST_FLAKEY`: Enable online tests that may be unreliable. Their success or failure may depend on network conditions, timing, solar flares, ghosts in the machine, etc.
23+
* `NGROK_TEST_ONLINE`: All online tests require this variable to be set and an authtoken in `NGROK_AUTHTOKEN`. Tests that require paid features will fail with appropriate error messages if your subscription doesn't support them.
2824

29-
This list may be incomplete and drift slightly as we add more tests and granularity. See the tests in `online_test.go` for the most accurate list.
25+
This list may be incomplete and drift slightly as we add more tests and granularity. See the tests in `internal/legacy/online_test.go` and `integration_test.go` for the most accurate implementations.

README.md

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,51 @@
11
# ngrok-go
22

3-
[![Go Reference](https://pkg.go.dev/badge/golang.ngrok.com/ngrok.svg)](https://pkg.go.dev/golang.ngrok.com/ngrok)
3+
[![Go Reference](https://pkg.go.dev/badge/golang.ngrok.com/ngrok/v2.svg)](https://pkg.go.dev/golang.ngrok.com/ngrok/v2)
44
[![Go](https://github.com/ngrok/ngrok-go/actions/workflows/buildandtest.yml/badge.svg)](https://github.com/ngrok/ngrok-go/actions/workflows/buildandtest.yml)
55
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ngrok/ngrok-rust/blob/main/LICENSE-MIT)
66

77

8-
[ngrok](https://ngrok.com) is a simplified API-first ingress-as-a-service that adds connectivity, security, and observability to your apps.
8+
[ngrok](https://ngrok.com) is an API gateway cloud service that forwards to
9+
applications running anywhere.
910

10-
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.
11+
ngrok-go is an open source and idiomatic Go package for embedding ngrok
12+
networking directly into your Go applications. If you've used ngrok before, you
13+
can think of ngrok-go as the ngrok agent packaged as a Go library.
1114

12-
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.
13-
14-
See [`examples/http/main.go`](/examples/http/main.go) for example usage, or the tests in [`online_test.go`](/online_test.go).
15+
ngrok-go enables you to serve Go apps on the internet in a single line of code
16+
without setting up low-level network primitives like IPs, certificates, load
17+
balancers and even ports! Applications using ngrok-go listen on ngrok's global
18+
cloud service but they receive connections using the same interface
19+
(net.Listener) that any Go app would expect if it listened on a local port.
1520

1621
For working with the [ngrok API](https://ngrok.com/docs/api/), check out the [ngrok Go API Client Library](https://github.com/ngrok/ngrok-api-go).
1722

1823
## Installation
1924

20-
The best way to install the ngrok agent SDK is through `go get`.
25+
Install ngrok-go with `go get`.
2126

2227
```sh
23-
go get golang.ngrok.com/ngrok
28+
go get golang.ngrok.com/ngrok/v2
2429
```
2530

2631
## Documentation
2732

28-
A full API reference is included in the [ngrok go sdk documentation on pkg.go.dev](https://pkg.go.dev/golang.ngrok.com/ngrok). Check out the [ngrok Documentation](https://ngrok.com/docs) for more information about what you can do with ngrok.
29-
30-
For additional information, be sure to also check out the [ngrok-go launch announcement](https://ngrok.com/blog-post/ngrok-go)!
33+
- [ngrok-go API Reference](https://pkg.go.dev/golang.ngrok.com/ngrok/v2) on pkg.go.dev.
34+
- [ngrok Documentation](https://ngrok.com/docs) for what you can do with ngrok.
35+
- [Examples](./examples) are another great way to get started.
36+
- [ngrok-go launch announcement](https://ngrok.com/blog-post/ngrok-go) for more context on why we built it. The examples in the blog post may be out of date for the new API.
3137

3238
## Quickstart
3339

34-
For more examples of using ngrok-go, check out the [/examples](/examples) folder.
35-
36-
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.
40+
The following example starts a Go web server that receives traffic from an
41+
endpoint on ngrok's cloud service with a randomly-assigned URL. The ngrok URL
42+
provided when running this example is accessible by anyone with an internet
43+
connection.
3744

38-
The ngrok authtoken is pulled from the `NGROK_AUTHTOKEN` environment variable. You can find your authtoken by logging into the [ngrok dashboard](https://dashboard.ngrok.com/get-started/your-authtoken).
45+
You need an ngrok authtoken to run the following example, get yours from the
46+
[ngrok dashboard](https://dashboard.ngrok.com/get-started/your-authtoken).
3947

40-
You can run this example with the following command:
48+
Run this example with the following command:
4149

4250
```sh
4351
NGROK_AUTHTOKEN=xxxx_xxxx go run examples/http/main.go
@@ -52,8 +60,7 @@ import (
5260
"log"
5361
"net/http"
5462

55-
"golang.ngrok.com/ngrok"
56-
"golang.ngrok.com/ngrok/config"
63+
"golang.ngrok.com/ngrok/v2"
5764
)
5865

5966
func main() {
@@ -63,16 +70,16 @@ func main() {
6370
}
6471

6572
func run(ctx context.Context) error {
66-
ln, err := ngrok.Listen(ctx,
67-
config.HTTPEndpoint(),
68-
ngrok.WithAuthtokenFromEnv(),
69-
)
73+
// ngrok.Listen uses ngrok.DefaultAgent which uses the NGROK_AUTHTOKEN
74+
// environment variable for auth
75+
ln, err := ngrok.Listen(ctx)
7076
if err != nil {
7177
return err
7278
}
7379

74-
log.Println("Ingress established at:", ln.URL())
80+
log.Println("Endpoint online", ln.URL())
7581

82+
// Serve HTTP traffic on the ngrok endpoint
7683
return http.Serve(ln, http.HandlerFunc(handler))
7784
}
7885

@@ -81,6 +88,15 @@ func handler(w http.ResponseWriter, r *http.Request) {
8188
}
8289
```
8390

91+
## Examples
92+
93+
There are many great examples you can copy to get started:
94+
95+
- [Creating a TCP endpoint](./examples/tcp/) and handling TCP connections directly.
96+
- [Forwarding to another URL](./examples/forward/) instead of handling connections yourself.
97+
- [Adding Traffic Policy](./examples/traffic-policy/) in front of your app for authentication, rate limiting, etc.
98+
- [Integrating with slog](./examples/slog/) for structured logging
99+
84100
## Support
85101

86102
The best place to get support using ngrok-go is through the [ngrok Slack Community](https://ngrok.com/slack). If you find bugs or would like to contribute code, please follow the instructions in the [contributing guide](/CONTRIBUTING.md).
@@ -102,4 +118,4 @@ Changes to `ngrok-go` are tracked under [CHANGELOG.md](https://github.com/ngrok/
102118

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

105-
See [LICENSE](./LICENSE.txt) for details.
121+
See [LICENSE](./LICENSE.txt) for details.

TODO.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
TODO
2+
3+
- Fix #176
4+
- Add agent configuration file parsing with an AgentConfig struct
5+
- Wrap `Conn` objects returned by the listener with a type that can be used to determine if they are TLS-terminated or not
6+
- Remove the legacy package by folding all of its logic into the current package

0 commit comments

Comments
 (0)