ngrok

package module
v0.0.0-...-b2c225b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2021 License: BSD-3-Clause, MIT Imports: 12 Imported by: 0

README

ngrok-go

This client simplifies interaction with the ngrok API.

Example usage:

import ngrok "github.com/meterup/ngrok-go"

client := ngrok.New(ngrok.BaseURL, os.Getenv("NGROK_API_TOKEN"))
data := url.Values{}
data.Set("description", "ngrok-go")
cred, err := client.Creds.Create(context.TODO(), data)
if err != nil {
    log.Fatal(err)
}
fmt.Printf("created credential: %#v\n", cred)

The client does not implement the entire API, but it should be easy to add new endpoints following the existing pattern.

Documentation

Overview

Package ngrok simplifies interaction with the ngrok API.

This client is not endpoint compatible with the API - many endpoints are missing. Still, it should be trivial to add new *Service objects and endpoints, following the existing pattern.

For more information on the ngrok API, see the documentation:

https://ngrok.com/docs/ngrok-link#service-api

Example
package main

import (
	"context"
	"fmt"
	"log"
	"net/url"
	"os"

	ngrok "github.com/meterup/ngrok-go"
)

func main() {
	client := ngrok.New(ngrok.BaseURL, os.Getenv("NGROK_API_TOKEN"))
	data := url.Values{}
	data.Set("description", "ngrok-go")
	cred, err := client.Creds.Create(context.TODO(), data)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("created credential: %#v\n", cred)
}
Output:

Index

Examples

Constants

View Source
const BaseURL = "https://api.ngrok.com"
View Source
const Version = "0.1"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*rest.Client

	Creds         *CredService
	ReservedAddrs *ReservedAddrService
	// contains filtered or unexported fields
}

func New

func New(baseURL string, token string) *Client

func (*Client) CreateResource

func (c *Client) CreateResource(ctx context.Context, pathPart string, data url.Values, v interface{}) error

CreateResource makes a POST request to the given resource.

func (*Client) DeleteResource

func (c *Client) DeleteResource(ctx context.Context, pathPart string, sid string) error

func (*Client) GetResource

func (c *Client) GetResource(ctx context.Context, pathPart string, sid string, v interface{}) error

GetResource retrieves an instance resource with the given path part (e.g. "/Messages") and sid (e.g. "MM123").

func (*Client) ListResource

func (c *Client) ListResource(ctx context.Context, pathPart string, data url.Values, v interface{}) error

func (*Client) MakeRequest

func (c *Client) MakeRequest(ctx context.Context, method string, pathPart string, data url.Values, v interface{}) error

Make a request to the ngrok API.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, path string, body io.Reader) (*http.Request, error)

NewRequest creates a new signed request. The base URL will be prepended to the path, and the user-agent will also be attached.

func (*Client) UpdateResource

func (c *Client) UpdateResource(ctx context.Context, pathPart string, sid string, data url.Values, v interface{}) error

type Cred

type Cred struct {
	// Only present on the response from a Create request, otherwise empty
	Token       string    `json:"token"`
	Description string    `json:"description"`
	ACL         []string  `json:"acl"`
	CreatedAt   time.Time `json:"created_at"`
	ID          string    `json:"id"`
	Metadata    string    `json:"metadata"`
	URI         string    `json:"uri"`
}

https://ngrok.com/docs/ngrok-link#list-credentials

type CredService

type CredService struct {
	// contains filtered or unexported fields
}

func (*CredService) Create

func (c *CredService) Create(ctx context.Context, data url.Values) (*Cred, error)

Create a new Credential. https://ngrok.com/docs/ngrok-link#create-credential

func (*CredService) Delete

func (c *CredService) Delete(ctx context.Context, id string) error

type Region

type Region string
const RegionAP Region = "ap"
const RegionAU Region = "au"
const RegionEU Region = "eu"
const RegionUS Region = "us"

type ReservedAddr

type ReservedAddr struct {
	Addr        string    `json:"addr"`
	CreatedAt   time.Time `json:"created_at"`
	Description string    `json:"description"`
	ID          string    `json:"id"`
	Metadata    string    `json:"metadata"`
	Region      string    `json:"region"`
	URI         string    `json:"uri"`

	EndpointConfiguration map[string]string `json:"endpoint_configuration"`
}

https://ngrok.com/docs/ngrok-link#list-reserved-addrs

type ReservedAddrService

type ReservedAddrService struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL