New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/ngrok/ngrok-api-go/v4

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/ngrok/ngrok-api-go/v4

  • v4.0.1
  • Source
  • Go
  • Socket score

Version published
Created
Source

ngrok API client library for Golang

This library wraps the ngrok HTTP API to make it easier to consume in Go.

Installation

Installation is as simple as using go get.

go get github.com/ngrok/ngrok-api-go/v4

Documentation

A quickstart guide and a full API reference are included in the ngrok go API documentation on pkg.go.dev

Quickstart

Please consult the documentation for additional examples.

Create an IP Policy that allows traffic from some subnets

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/ngrok/ngrok-api-go/v4"
	"github.com/ngrok/ngrok-api-go/v4/ip_policies"
	"github.com/ngrok/ngrok-api-go/v4/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

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/ngrok/ngrok-api-go/v4"
	"github.com/ngrok/ngrok-api-go/v4/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
}

FAQs

Package last updated on 06 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc