api

command
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

api — a public HTTP API with no listener and no config

A Go program that becomes publicly reachable by calling one function. It opens no port, has no URL of its own, and contains no hub configuration: pkg/expose reads ~/.holt/config.yaml, enrolls with the hub its default profile names, and serves the handler back down the tunnel.

This is holt expose turned inside out. The CLI exposes a port something else is listening on; this exposes the handler in the program itself, so there is no local hop and nothing to firewall.

Run it

You need a hub in ~/.holt/config.yaml. Any profile will do:

default_profile: local

profiles:
  local:
    admin_url: http://127.0.0.1:7201

Then:

holt hub --ui          # in one terminal, if you have no hub yet
go run ./examples/api  # in another

It prints where it landed:

serving at https://demo-api.peers.example.com/time

...or, on a header-routed hub, the URL plus the header that names it. Either way the address is known before the tunnel is dialed, because expose.New asks the hub and returns; peer.Serve(ctx) is what blocks.

The whole integration

peer, err := expose.New(ctx, api, expose.WithPeerName("demo-api"))
if err != nil {
	log.Fatal(err)
}

fmt.Println("serving at", peer.URL)
log.Fatal(peer.Serve(ctx))

Or, when the address does not need printing, one line:

log.Fatal(expose.Serve(ctx, api))

Identity

With no WithPeerName the peer enrolls under a generated id (brisk-otter-4f2a), which is fine for something short-lived and wrong for a service: a fresh enrollment on every start means a new hostname on every start.

For anything long-lived, mint an identity once and give it to the program:

holt enroll demo-api
HOLT_TOKEN=<paste> go run ./examples/api

$HOLT_TOKEN (or expose.WithToken) skips enrollment entirely, so the peer keeps its name and its URL across restarts. Mind the hub's --token-ttl: the token is checked on every attach, not just the first.


← examples · Library

Documentation

Overview

Command api is a Go HTTP API that is publicly reachable without listening on anything. It reads the hub out of ~/.holt/config.yaml, enrolls itself, and serves its handler back down the tunnel:

go run ./examples/api

It prints the URL it just became reachable at, then serves until Ctrl-C. No port, no ingress, no configuration in this file: the profile already knows the hub, including any credentials the proxy in front of it wants.

Jump to

Keyboard shortcuts

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