https://github.com/ngrok/ngrok-api-go
ngrok API client library for Golang
https://github.com/ngrok/ngrok-api-go
go golang ngrok reverse-proxy
Last synced: 2 months ago
JSON representation
ngrok API client library for Golang
- Host: GitHub
- URL: https://github.com/ngrok/ngrok-api-go
- Owner: ngrok
- License: mit
- Created: 2021-05-14T22:13:38.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-26T17:14:07.000Z (2 months ago)
- Last Synced: 2025-04-03T01:44:38.742Z (2 months ago)
- Topics: go, golang, ngrok, reverse-proxy
- Homepage: https://ngrok.com
- Size: 373 KB
- Stars: 53
- Watchers: 4
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# ngrok API client library for Golang
[](https://github.com/ngrok/ngrok-api-go/actions/workflows/ci.yml)
[](https://pkg.go.dev/github.com/ngrok/ngrok-api-go/v7)This library wraps the [ngrok HTTP API](https://ngrok.com/docs/api) to make it
easier to consume in Go.For creating ngrok tunnels directly from your Go application, check out the [ngrok Go Agent SDK](https://github.com/ngrok/ngrok-go) instead.
## Installation
Installation is as simple as using `go get`.
go get github.com/ngrok/ngrok-api-go/v7
## Support
The best place to get support using this library is through the [ngrok Slack Community](https://ngrok.com/slack). If you find any bugs, please contribute by opening a [new GitHub issue](https://github.com/ngrok/ngrok-api-go/issues/new/choose).
## Documentation
A quickstart guide and a full API reference are included in the [ngrok go API documentation on pkg.go.dev](https://pkg.go.dev/github.com/ngrok/ngrok-api-go/v6)
## Quickstart
Please consult the [documentation](https://pkg.go.dev/github.com/ngrok/ngrok-api-go/v6) for additional examples.
### Create an IP Policy that allows traffic from some subnets
```go
package mainimport (
"context"
"fmt"
"os""github.com/ngrok/ngrok-api-go/v7"
"github.com/ngrok/ngrok-api-go/v7/ip_policies"
"github.com/ngrok/ngrok-api-go/v7/ip_policy_rules"
)func main() {
fmt.Println(example(context.Background()))
}func example(ctx context.Context) error {
// create clients to api resources
clientConfig := ngrok.NewClientConfig(os.Getenv("NGROK_API_KEY"))
policies := ip_policies.NewClient(clientConfig)
policyRules := ip_policy_rules.NewClient(clientConfig)// create the ip policy
policy, err := policies.Create(ctx, &ngrok.IPPolicyCreate{})
if err != nil {
return err
}
fmt.Println(policy)// create rules for each cidr
for _, cidr := range []string{"24.0.0.0/8", "12.0.0.0/8"} {
rule, err := policyRules.Create(ctx, &ngrok.IPPolicyRuleCreate{
CIDR: cidr,
IPPolicyID: policy.ID,
Action: ngrok.String("allow"),
})
if err != nil {
return err
}
fmt.Println(rule)
}
return nil
}
```### List all online tunnels
```go
package mainimport (
"context"
"fmt"
"os""github.com/ngrok/ngrok-api-go/v7"
"github.com/ngrok/ngrok-api-go/v7/tunnels"
)func main() {
fmt.Println(example(context.Background()))
}func example(ctx context.Context) error {
// construct the api client
clientConfig := ngrok.NewClientConfig(os.Getenv("NGROK_API_KEY"))// list all online tunnels
tunnels := tunnels.NewClient(clientConfig)
iter := tunnels.List(nil)
for iter.Next(ctx) {
fmt.Println(iter.Item())
}
if err := iter.Err(); err != nil {
return err
}
return nil
}
```