trycloudflared

package module
v0.0.0-...-870ef80 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2025 License: ISC Imports: 25 Imported by: 0

README

trycloudflared

zero-configuration library to use Cloudflare Tunnel in your Go application without deploying a separate service.

Note that this ties you to a particular version of cloudflared, so you may want to use a separate service in production in case they break the API.

as seen in: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/do-more-with-tunnels/trycloudflare/#use-trycloudflare

cloudflared tunnel --url http://localhost:12345

equivalent code if you want to use it in your Go application:

package main

import (
	"fmt"
	"context"
	"github.com/wizzard0/trycloudflared"
)

func main() {
	// start your http server on port 12345
	// e.g. http.ListenAndServe(":12345", nil)
	// ...
	ctx, cancel := context.WithCancel(context.Background())
	
	// this will expose localhost:12345 via https://something.trycloudflare.com
	url, err := trycloudflared.CreateCloudflareTunnel(ctx, 12345)
	if err != nil {
		panic(err)
	}

	// url is the URL of the tunnel
	fmt.Println(url)
	// do something with the tunnel
	// ...
	// cancel the tunnel when done
	cancel()
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version   = "DEV"
	BuildTime = "unknown"
	BuildType = ""
)

Functions

func CreateCloudflareTunnel

func CreateCloudflareTunnel(ctx context.Context, port int) (string, error)

Types

type CreateTunnelError

type CreateTunnelError struct {
	Code    int
	Message string
}

type CreateTunnelResponse

type CreateTunnelResponse struct {
	Success bool                `json:"success"`
	Result  TunnelCredentials   `json:"result"`
	Errors  []CreateTunnelError `json:"errors"`
}

type TunnelCredentials

type TunnelCredentials struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	Hostname   string `json:"hostname"`
	AccountTag string `json:"account_tag"`
	Secret     []byte `json:"secret"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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