share

package
v1.0.35 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitBasicAuth

func SplitBasicAuth(auth string) (user, pass string, ok bool)

SplitBasicAuth splits a "user:pass" string.

Types

type Assignment

type Assignment struct {
	Subdomain string `json:"subdomain,omitempty"`
	Error     string `json:"error,omitempty"`
}

Assignment is the JSON response from the relay after registration.

type Client

type Client struct {
	RelayAddr string
	Handler   http.Handler // handler to serve requests (e.g. StaticServer)
	BasicAuth string       // "user:pass" or "" for no auth
	// contains filtered or unexported fields
}

Client tunnels a local HTTP server through a relay to expose it publicly.

func New

func New(relayAddr string, handler http.Handler, basicAuth string) *Client

New creates a new share client. handler is the http.Handler to serve (typically a StaticServer). basicAuth should be "user:pass" or empty for no auth.

func (*Client) Close

func (c *Client) Close() error

Close shuts down the yamux session.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context, version string) (string, error)

Connect dials the relay, registers, and establishes a yamux session. Returns the assigned subdomain on success.

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run serves HTTP requests from the relay using the configured Handler. It creates an http.Server backed by a yamux-based net.Listener. Blocks until the context is cancelled or the session dies.

func (*Client) RunWithReconnect

func (c *Client) RunWithReconnect(ctx context.Context, version string, onConnect func(subdomain string), onDisconnect func(err error))

RunWithReconnect runs the client with automatic reconnection on failure. It calls onConnect with the subdomain each time a connection is established, and onDisconnect when the connection drops.

func (*Client) Subdomain

func (c *Client) Subdomain() string

Subdomain returns the currently assigned subdomain.

type Registration

type Registration struct {
	Version   string `json:"version"`
	BasicAuth string `json:"basic_auth,omitempty"`
}

Registration is the JSON message sent to the relay on connect.

Jump to

Keyboard shortcuts

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